Bluefire Bluefire - 6 months ago 10
Java Question

Why does importing a class not import all of its dependencies?

If I want to use an

ArrayList
in my code, I need to import
java.util.ArrayList
. If I also want to use a
List
, I have to import
java.util.List
. Why is this needed?
ArrayList
inherits from
List
, and thus uses code from it. Why does that not carry over to my class? Surely if
ArrayList
imports
List
, and my class in turn imports
ArrayList
, then
List
should be defined in my class?

Answer

import is just a syntactic feature that lets you avoid writing out the full package every time you use a classname.

You do not need to import dependencies at all.