Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

java Method class

hi,

why java.lang package has class called Method.

what are other classes there in that and what is purpose of those classes.

when do we need to use them

please advise
SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

right.

i also see methods like setShortDescription. I wonder what is use of args here and also methods like setShortDescription. please advise

     Class cl = Xyz.class;
         Class args[] = { };
         Method cToF = cl.getMethod("cT", args);
         MethodDescriptor cTDesc = new MethodDescriptor(cToF);
         cTDesc.setShortDescription("modify c to f");
Avatar of dpearson
dpearson

That's moving into even more obscure corners.  Java has a concept of java beans that in some cases can be modified by external tools.  An example of this is using a debugger to connect into a running process and change the current logging level.

This API (I believe - I've never used it) supports that sort of operation.

This is way way off the beaten path.  I would recommend not delving into this area until you've mastered the basics - you will get very lost.

Doug
Avatar of gudii9

ASKER

helloMethod.call() ;

call() is other method on the hello() method?

please advise if there is any link with sample code to understand this atleast at high level.
Sure the Java tutorials cover this in depth:
https://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html

And yes "helloMethod.call()" is another way to call to the hello() method.  You get an object which represents the method itself (i.e. an object that represents a piece of program code) and then you call that object.

I see looking at the tutorial the actual method name is "invoke":
https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#invoke-java.lang.Object-java.lang.Object...-

So I should have said "helloMethod.invoke()" in my pseudo code.

As I mentioned earlier - this is advanced stuff.  You could program professionally for 10 years in Java and never need to use this stuff - so proceed with caution :)

Doug