File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Aliasing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Aliasing " Watch "Aliasing " New topic
Author

Aliasing

anil kumar bolisetti
Greenhorn

Joined: Jan 05, 2005
Posts: 6
We can give alias names in c/c++ by using typedef operator.
Is there any option like that in java.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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.


Mike Gershman
SCJP 1.4, SCWCD in process
anil kumar bolisetti
Greenhorn

Joined: Jan 05, 2005
Posts: 6
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

Joined: Mar 13, 2004
Posts: 1272
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Aliasing
 
Similar Threads
Q on static inner Classes
Release Announcement - "C++ in a Nutshell" - O'Reilly
tricky question
Job Band in infosys
I.O read and write same time?????