It seems really good. You are willing to tell us what static import will bring to the developer?
It allows programmers to do not have to prefix class names when using static members of the class. People do hope, so they often achieve so-called constant interfaces to achieve this effect:
// "Constant Interface" Antipattern - Do Not Use!
Public interface physics {
PUBLIC STATIC FINAL DOUBLE AVOGADROS_NUMBER = 6.02214199E23;
Public Static Final Double Boltzmann_Constant = 1.3806503E-23;
Public Static Final Double Electron_Mass = 9.10938188E-31;
}
Public class guacamole imports physics {
Public static void main (String [] args) {
Double Moles = ...;
Double Molecules = AvogAdros_Number * Moles;
...
}
}
This is a very bad approach: the interface is used to define types, not used to define constants. Guacamole uses the Physics constant to achieve details, and should not open public APIs. The result of doing this not only makes the user's user, but it also has a long-term commitment. Even if you are ready to override the GuAcamole class, you will not use these constants, you must also implement this interface. Because this class is dependent on your type of IMPLEMENTS Physics.
Static import (static import) provides a clear solution. It allows programmers to use a static member of a class without becoming a method of its subclass. It is very similar to the features of Package Import, but he just imports a static member of a class, and Package Import is imported from the package. Below is an example:
Import static org.iso.physics. *;
Class Guacamole {
Public static void main (String [] args) {
Double Molecules = AvogAdros_Number * Moles;
...
}
}
Note that whether Physics is still a class or a class, this program can work normally. If it just defines a constant, it should be defined as a class rather than an interface.
I understand. Can you tell me some convenience about metadata?
This is not too similar to some other features we discussed. It can also make development more easily, but require support for tool developers.
Many APIs now require a considerable number of template files. For example, when you define a JAX-RPC Web Service, you have to provide an interface and an implementation class:
Public interface coffeeorderif extends java.rmi.remote {
Public coffee [] getpricelist ()
Throws java.rmi.remoteexception;
Public String ORDERCOFEE (String Name, int Quantity)
Throws java.rmi.remoteexception;
}
Public Class CoffeeOrderImpl Implements CoffeeOrderif {
Public coffee [] getpricelist () {...
}
Public String ORDERCOFEE (String Name, Int Quantity) {
...
}
}
This example is copied directly from our Web Services Tutorial.
If there is a dollar data function, you don't have to write all these things. As long as the tag code allows the tool to know those code, the tool automatically generates the above code. Below is an example of a code supported by the dioogrammed function:
Import javax.xml.rpc. *;
Public class coffeeorder {
@Remote public coffee [] getpricelist () {
...
}
@Remote Public String ORDERCOFFEE (String Name, INT Quantity) {
...
}
}
All sample files are not!
Well, it is really simple. But you can't define all useful nature and construct all tools, isn't it?
Yes, JSR-175 just provides a framework to other developers, allowing them to define nature and constructors. Some of the other JSRs, such as JSR-181, define metadata of Web Services, is defined attributes. We expect this area to have more development.
Put forward, what new changes do you expect future Java languages?
This is not good. All my energy is now in Tiger, there is no time to consider what is the next change.
Do you still want to leave some other information?
Other most important thing is that Tiger is a developer-centric version. When James Gosling and his team introduced the Java language, Java's development is like a take-off rocket, the reason is that it touched the developer's mind and ignited their enthusiasm. The development of this version is still based on this idea.
I am very fortunate to have the opportunity to get the new features of these languages, and I find that it is a pleasure to work. I am sure that other developers will also do this. In the existing development language, Java is originally a very easy-to-use and productive language, and all the upcoming new features will greatly enhance the use of its fun and improve the productivity used to develop.