File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aliasing

 
anil kumar bolisetti
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can give alias names in c/c++ by using typedef operator.
Is there any option like that in java.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java uses interface where C++ would use typedef. The difference is that an interface can be the alias for any one of a set of otherwise unrelated classes that share some defined state and behavior, while a typedef represents a single entity.
 
anil kumar bolisetti
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mike for your reply.
But my question has been answered yet.
consider a C program as:
typedef float myfloat;
so we can declare a float variable as:
myfloat a;

My question is: Is there any provision to give alias name like this in java.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly are you trying to do?

I used typedef in C programs to make a struct act like a C++ class.

There are some new capabilitis in Java 5, like autoboxing and generics, that may meet your needs.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anil --

The answer is no. A common use for typedef is to, let's say, defer choosing between float and double, and allow you to easily change code that uses one to use the other. Java doesn't have any such feature.

Although this is inconvenient sometimes, the convenience in C/C++ comes at a price: if you look at a C/C++ program, you don't necessarily know what you're dealing with unless you look at all the header files included by the file you're looking at. In Java, what you see is what you get -- Java code isn't as "tricky" and is thus easier to understand.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic