• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

methods in a class

 
fadil alnassar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!

Is it possible in java to see how many methods i got or check if a method called 'blabla' is in the class.

what i want to do is that i neeed to provide a set of classes for a person who should add a class to classed i gave him and his class should include all functions or methods that i asked him to do so it will be like a marker system to test whther the person include all what i asked him for it so if possible i need to check if there is constructor or not, check the number of methods or check mame of methods and if possible any details for these methods like return vlaue and number of parameters.

i do not know if there is a API in JAVA provides these functionality but i wish some one can help me to acheive that.

apprecaite your help!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Have a look at the getMethod(), getMethods(), getDeclaredMethod(), getDeclaredMethods(), and related methods in the class java.lang.Class.
 
fadil alnassar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply !!

i am beginner in java can you give me an example of that.

thanks for your help !!
 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to look into java.lang.Class documentation. You have everything in place there. Well I'll give what you asked for just to pamper you

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at http://java.sun.com/docs/books/tutorial/reflect/index.html
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fadil alnassar:
thanks for reply !!

i am beginner in java can you give me an example of that.

thanks for your help !!


Reflection is an advanced concept, so if you can hold your breath, you can get to it when it's due. For now, if this is to help you understand more about methods in a class and such, you create javadocs for your classes and refer to them.
[ January 03, 2006: Message edited by: Stuart Ash ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fadil alnassar:

his class should include all functions or methods that i asked him to do


Why do you need to know this? It sounds to me that you are either:
1) writing some sort of exercise checking program
2) Writing an abstract base class with abstract methods

In the second case, a non-abstract class will have no abstract methods,
so that will force their implementation. But what are you really doing?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic