United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4194542 : class name aliasing

Details
Type:
Enhancement
Submit Date:
1998-12-03
Status:
Closed
Updated Date:
2007-07-24
Project Name:
JDK
Resolved Date:
2007-07-24
Component:
specification
OS:
linux,generic,windows_2000
Sub-Component:
language
CPU:
x86,generic
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.2.0,1.3.0,1.4.0,1.4.1,1.4.2
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:

Sub Tasks

Description

Name: diC59631			Date: 12/03/98


Obviously the two below operations will not
compile in the same java file.

import java.util.Date ;
import java.sql.Date ;

It would be nice to alias one such as below:

import java.util.Date ;
import java.sql.Date as SqlDate ;

Date    => java.util.Date
SqlDate => java.sql.Date

This way instead of leaving out the
import java.sql.Date line and having to
fully qualify the SQL Date class for every
usage, you'd only have to use the SqlDate
alias.

This becomes a much larger issue with package
names like:
  com.fake1.western.division.plane.Fuel ;
  com.fake2.tiger.landbased.vehicle.Fuel ;

Especially when you need to use both types of
Fuel, but can only use the shortend version
for one of them at most.

"import .. as .." is not a new concept, and
I'm surprised that it wasn't incorporated into
the language specification from the beginning.
(Review ID: 43613)
======================================================================

An alternative syntax is proposed in RFE 4478140:

import jlang=java.lang.*;
alias jlang=java.lang;

The need for an extra keyword is not clear.

###@###.### 2005-04-17 07:20:05 GMT

                                    

Comments
WORK AROUND



Name: diC59631			Date: 12/03/98


Always use fully qualified class names.
======================================================================
                                     
2004-06-11
EVALUATION

4983159 is the master CR for type aliasing.
                                     
2007-07-24
EVALUATION

This is a minor bit of syntactic sugar. I am not convinced that it is very important in practice. The usual arguments about destabilizing the language,
high bar for changes and creeping featurism apply.

gilad.bracha@eng 1998-12-03
                                     
1998-12-03



Hardware and Software, Engineered to Work Together