Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java subclass not importing imports from abstract superclass?

i have an abstract class that many other classes extend.

They should all import about 7 packages needed, but when i import them in the abstract class and not the subclasses, the compiler errors. Is this not possible or am i just not doing it the right way? thanks!

like image 314
matt Avatar asked Dec 05 '22 23:12

matt


1 Answers

Imports do not get automagically added to subclasses.

An import simply allows the programmer to use a shorter name for a type (say, List<T>) rather than the type's fully qualified name (java.util.List<T>). It does not have anything to do with inheritance.

If you're using an IDE, such as Eclipse, imports can automatically be added for you - but that's still only an IDE function. The source code of every class file must have its own imports (unless you use fully qualified names everywhere, and !@#$ that).

like image 121
Matt Ball Avatar answered Jan 26 '23 00:01

Matt Ball