Reputation: 1315
I am using ProGAL
package. There are two different classes, ProGAL.geom2d.Point
and ProGAL.geom3d.Point
. Both are referred as Point
. When I import one, I only can use the other by typing the full path. For instance:
import ProGAL.geom3d.Point;
//...
Point pointIn3D = new Point(1,2,3);
ProGAL.geom2d.Point pointIn2D = new ProGAL.geom2d.Point(4,5);
I want to use something like
#define ProGAL.geom3d.Point point3d
#define ProGAL.geom2d.Point point2d
Just like in C++. Is it possible with Java?
Usage would be like:
point3d pointIn3D = new point3d(1,2,3);
point2d pointIn2D = new point2d(1,2,3);
Upvotes: 1
Views: 82
Reputation: 6432
No its not possible as there are no #typedef
or #define
in Java (no preparser). You could try writing another class to encapsulate the one you want to rename or just have lots of code commments.
I do want to note that I don't think that you should try to change the name of the class. It has its name for a reason. If you are going to use it within another class it is really useful for a person to know the actual class that they are working with. This I think is good read/usability. I don't think its good to put smoke screens where ones don't need to exist. The name is descriptive enough.
Upvotes: 1
Reputation: 1315
The answer is no. As stated in this link, typedef
and #define
keywords are accepted as complications and removed in Java because they reduce readibility of the code.
Upvotes: 1
Reputation: 1461
No it's not possible since Java does not allow precompilation instruction.
Upvotes: 1