yegor256/rehttp

Usage of static fields

Open

#12 opened on Sep 5, 2017

View on GitHub
 (11 comments) (0 reactions) (0 assignees)Java (3 forks)github user discovery
bughelp wantedscope

Repository metrics

Stars
 (43 stars)
PR merge metrics
 (PR metrics pending)

Description

@yegor256, I cannot figure out what are criteria for making a field static or not. E.g.

    final class TkBadge implements Take {

    /**
     * XSL.
     */
    private static final XSL SVG = XSLDocument.make(
        TkBadge.class.getResourceAsStream("badge.xsl")
    );

After reading your books I often hesitate to make something static but sometimes pretty constant non-static fields looks weird. Where is the line which should be drawn?

I think it is more like OK than not?:

private static final String REV = Manifests.read("Rehttp-Revision");

Bit why this isn't really a ctor?

/**
     * Ctor.
     * @param base Base
     * @return App
     * @throws IOException If fails
     */
    private static Take app(final Base base) throws IOException {

Well, I guess it should be fixed as long as the methods aren't being used in a static context or in this(...):

    // DyTake.java 
    private static int code(final Response response) throws IOException {
    private static Request request(final Request req, final URI uri) 

So, what is a legal use of static fields? Is it OK for really definitions which are unlikely will need to be overriden (say even in the unit-tests)?

Contributor guide