Skip to main content

Shortcut for methods and attributes

2 replies [Last post]
Joined: 2005-09-02

I very often need to refer to attribute. For example in hibernate you use for Criteria searches attribute name. However if we would like to avoid mistypes and keep code clean it will be very helpful to have shortcut similar to ".class" for attributes maybe also for functions e.g:
class MySample {
String a;
Integer b,
public static void funcc() {
Log=new Log(MySample.class);, "mama%");

Generally speaking I will like to have following shortcuts with following return paramters:
AnyClass.class -> java.lang.Class
AnyAttribute.field -> java.lang.reflect.Field
AnyAttribute.class -> java.lang.Class
AnyMethod.method -> java.lang.reflect.Method
AnyMethod.class -> java.lang.Class

Plus one beauty:
With generics it will be great because than we can have methods with following signs:
public void eq(Field>, String)
what mean any field from DBObject or inherited class. Of course Field has to be "generified" before.

Is this feasible?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-12-02

in other words: you want to abandon private and protected fields, enabling you to access everything at all times by directly accessing the field itself.

Bye bye encapsulation, type safety, and everything else that makes Java Java.

Joined: 2005-09-02

No, absolutely not. Shortcut for field is same as Sample.class.getDeclaredFields("firstname");
However with shortcut we should avoid mistype in string field by compile time checks. Code is more save this way.