Is there a way to shorten type names in java. Something similar to typedef
in c++ or similar to the usage of namespaces?
For example if I have the type "org.w3c.dom.Node" and I don't want to write
that full name every time, but also don't want to do import on the whole file
but just localy define the type of "Node" to be "org.w3c.dom.Node" on one method?
Asked
Active
Viewed 958 times
3

tomermes
- 22,950
- 16
- 43
- 67
-
How many `Node` class do you have? If it's just your Node and w3c, rename your class. – user802421 Apr 01 '12 at 09:36
-
1I think this is a similar issue here http://stackoverflow.com/questions/5604390/how-do-i-create-some-variable-type-alias-in-java Maybe that will help you.. – Aminesrine Apr 01 '12 at 09:37
-
Maybe use templates. Not at all what you wanted though.. – keyser Apr 01 '12 at 10:07
2 Answers
5
No, there's no way to create an alias "locally" (I take it by "locally" you mean within a method, since you said you don't want to do an import
at the top of the file, which is "local" to the file).

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875
2
You don't want to import that class for the whole file, but what about moving the method(s) that require org.w3c.dom.Node to a new file that does have that import?

dldnh
- 8,923
- 3
- 40
- 52