문제

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 only static 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?

다른 팁

No, you can't do that.

In order to import method or variable it should be public and static. Constructors and local variables cannot be static.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top