[SUGGESTION]: Define aliases when importing multiple classes with same classname

CHAUVET Guillaume gchauvet at zatarox.com
Fri Oct 10 04:50:51 UTC 2014


Dear OpenJDK community,

I would like to submit you a potential new Java feature already existing 
in Eiffel language : renaming classes/interfaces when importing them. 
The goal is to improve the clashnames resolution when importing some 
classes with the same classname but provided from different packages by 
adding a classname alias mechanism. Below, a simple use case that 
display how this potential new syntax :

Snippet class
==================
import javax.management.Query;
import javax.persistence.Query as PersistenceQuery;
import org.apache.lucene.search.Query as LucentQuery;

public class Snippet {

  private javax.persistence.Query q1;	// Direct classname resolution
  private PersistenceQuery q2;		// Using alias classname of 
javax.persistence.Query
  private Query q3;			// Using default imported class : 
javax.management.Query
  private LucentQuery q4;		// Using alias classname of 
org.apache.lucene.search.Query

  public PersistenceQuery getPersistence() {
   return q2;
  }
}

Caller class
==================
Snippet s = new Snippet();
s.getPersistence(); // return javax.persistence.Query, not the internal 
alias used in class definition


I'm ready to involved to implement this new feature by contributing to 
the OpenJDK development effort.

Best regards




More information about the discuss mailing list