class or method alias in java

前端 未结 8 1074
青春惊慌失措
青春惊慌失措 2020-12-10 00:31

I have long java class and method names

LONGGGGGGGGGGGGGGGClass.longggggggggggggggggggggggggMethod();

I want to alias it to g.m();

8条回答
  •  情歌与酒
    2020-12-10 00:51

    Actually there is a way to get 1/2 of what you're after.

    Looking at your example:

    LONGGGGGGGGGGGGGGGClass.longggggggggggggggggggggggggMethod();
    

    It appears that longggggggggggggggggggggggggMethod is static. (If it weren't, you'd be prefixing it with a variable name, which you control the size of.)

    You can use Java's static import feature to 'alias' or import the static methods of the LONGGGGGGGGGGGGGGGClass into your own class' namespace. Instead of the above code, you would only have to write this:

    longggggggggggggggggggggggggMethod();
    

提交回复
热议问题