java - Nesting calls to static methods -
i want below, not work. objective able nest function calls static helper classes more brevity.
public class statichelper { public static class<statichelper> dosomthing() { system.out.println("i did !!"); return statichelper.class; } public static class<statichelper> dosomthingelse() { system.out.println("i did else !!"); return statichelper.class; } public static void main(string[] args) { // not compiles statichelper.dosomthing().dosomthingelse(); } }
is possible? if simple example above helpful.
i guess want this.
public class statichelper { private final static statichelper instance = new statichelper(); public static statichelper dosomthing(){ system.out.println("i did !!"); return instance; } public static statichelper dosomthingelse(){ system.out.println("i did else !!"); return instance; } public static void main(string[] args) { statichelper.dosomthing().dosomthingelse(); } }
or way
public class statichelper { public static someclass dosomthing(){ return new someclass().dosomthing(); } public static someclass dosomthingelse(){ return new someclass().dosomthingelse(); } public static void main(string[] args) { statichelper.dosomthing().dosomthingelse(); } private static class someclass { public someclass dosomthing(){ system.out.println("i did !!"); return this; } public someclass dosomthingelse(){ system.out.println("i did else !!"); return this; } } }
Comments
Post a Comment