Can I refer to a specific package in java with a variable name?
Say I want to access a method foo()
in a nested structure at stuff.biscuit.jelly.sausages.foo()
, (where jelly
is a package and sausages
is a class)
can I set a variable var
such that var = stuff.biscuit.jelly.sausages
, and then access foo()
via:
var.foo()
? (or something vaguely similar)
edit:
regarding imports, any recommendations if i want to use lots of different foo() methods, such as:
stuff.biscuit.jelly.cherry.foo()
stuff.biscuit.jelly.apple.foo()
stuff.biscuit.jelly.strawberry.foo()
?
edit: the proposed duplicate is unrelated. it's talking about using the same name for a variable as a package. i'm talking about referring to a nested package with a variable.