需要做什么来实现“import ... as ...”在java中 [英] What need to be done to implement "import ... as ..." in java
问题描述
如果这是可能的,java编译器的什么部分需要重新设计为具有import as语句,因此代码可以看起来像这样:
If this is possible, what part of java compiler need to be re-engineered to has an "import as" statement, so codes can look like this way:
import java.util.Date;
import mypackage.Date as MyDate;
//...
javaDate = new Date();
myDate = new MyDate();
更多的是,需要获得这种语法:
Even more, what need to get this kind of syntax:
import java.util.Date;
import path.to.mypackage as MP;
//...
javaDate2 = new Date();
myDate2 = new MP.Date();
现有代码会导致什么问题?
And what trouble it will cause for existing codes?
推荐答案
这显然需要对Java编译器进行更改。如果你真的有兴趣做这样的事情,那么看看 OpenJDK 项目,您将在其中找到Oracle Java的源代码编译器和运行时环境。
This obviously requires changes to the Java compiler. If you're really interested in doing something like this, then look at the OpenJDK project, where you will find the source code for Oracle's Java compiler and runtime environment.
如果你想将它作为未来版本Java的一个新特性,那么你必须经过 Java社区流程。
If you want to propose this as a new feature for a future version of Java, then you'd have to go through the Java Community Process.
这篇关于需要做什么来实现“import ... as ...”在java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!