Or can this just be done for methods/fields/enum constants?
In Java, is it possible to (statically) import constructors or local variables?
474 Views Asked by John Assymptoth At
2
Or can this just be done for methods/fields/enum constants?
Constructors in Java can't be invoked directly (only via
new
), so you can't import them apart from the containing class. Since the only use of a constructor, is to create a new instance of the class, you need to import the whole class anyway, and this implies the constructor. Not to mention that if anything, it is an instance method, and you can import onlystatic
methods and variables.Local variables have no existence outside their scope, i.e. they are not tied to a class, only to a code block inside a method [Update](or a static/instance initializer)[/Update]. So how would you import them?