gudii9
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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
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
ASKER
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