When the type name is too long, in C# i can create alias like this:
using Dict = System.Collections.Generic.Dictionary<string, string>;
And I can use it like this:
Dict d = new Dict();
d.Add("key", "value");
Can I create an alias similar to this in Java?
You can't create an alias, but you can import
packages (JLS 7.5 Import Declarations) so that you don't have to fully qualify class names in that package.
import java.util.*;
import java.lang.reflect.Field;
....
Set<Field> s = ... // Set is in java.util
You can also do a static import
(guide), though this practice should be limited.
import static java.util.Arrays.asList;
...
System.out.println(asList(1, 2, 3));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With