yegor256/rehttp

Usage of static fields

Open

#12 aperta il 5 set 2017

Vedi su GitHub
 (11 commenti) (0 reazioni) (0 assegnatari)Java (3 fork)github user discovery
bughelp wantedscope

Metriche repository

Star
 (43 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

@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)?

Guida contributor