Feature request: aliasing classes at import

Kelly O'Hair kelly.ohair at oracle.com
Thu Jul 14 17:52:04 PDT 2011


Kind of looks like C macros:

#define UDate java.util.Date
#define SDate  java.sql.Date

Oh, that would be bad right?  Did someone say Java shall not have macros? ;^)

-kto


On Jul 14, 2011, at 5:17 PM, neugens.limasoftware at gmail.com wrote:

> I king like this idea too, although the situations where this problem really occurs are probably limited and can be addressed by some simple factoring of the code, I think this could be a nice addition.
> 
> Said that, I also see a high risk as drawback, in that this could provide a maintainance problem, making the code less readable and more difficult to follow without a proper IDE.
> 
> Mario
> -- 
> Sent from HTC Desire...
> 
> pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
> Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF
> 
> http://www.icedrobot.org
> 
> Proud GNU Classpath developer: http://www.classpath.org/
> Read About us at: http://planet.classpath.org
> OpenJDK: http://openjdk.java.net/projects/caciocavallo/
> 
> Please, support open standards:
> http://endsoftpatents.org/
> 
> 
> ----- Reply message -----
> Da: "Ivan Krylov" <Ivan.Krylov at oracle.com>
> Data: ven, lug 15, 2011 01:51
> Oggetto: Feature request: aliasing classes at import
> A: <jdk8-dev at openjdk.java.net>
> 
> I would not limit this than just to class names but rather expand idea 
> of selective alliasing to methods and fields.
> 
> just my 0.02
> 
> On 7/10/11 6:02 AM, Behrang Saeedzadeh wrote:
>> Hi,
>> 
>> For a long time it was not very common to encounter a situation in
>> which two classes with the same name but in different packages had to
>> be imported and used frequently in the same file. In fact till
>> recently the only case I used to encounter every now and then was when
>> I had to import java.util.Date and java.sql.Date in the same class.
>> 
>> However recently it's more likely to encounter a situation like this.
>> Some libraries have annotations and classes that use the same name.
>> Also some APIs such as Eclipse EMF use class names (e.g. Package) that
>> clash with Java class names and there are cases that both of them
>> should be used frequently and using FQ names makes the source code
>> very verbose and ugly.
>> 
>> It would be nice to be able to import a class under a desired name at
>> import time, e.g.:
>> 
>> import java.util.Date : UDate;
>> import java.sql.Date : SDate;
>> 
>> Some other languages support this feature and I think it's a small
>> coin-scale feature that would be nice to be added to Java. What do you
>> think?
>> 
>> Cheers,
>> Behrang Saeedzadeh
>> http://www.behrang.org



More information about the jdk8-dev mailing list