Given the following scala class :
class Student (_name:String, _id:Long) {
private var name:String = _name;
private var id:Long = _id;
// 2nd C'tor
def this(_name:String) = this(_name,0);
// 3rd C'tor
def this(_id:Long) = this("No Name",_id);
def printDetails() {
println("The student's name is : " + name);
println("The student's id is : " + id);
}
}
and the following Java class:
public class StudentReflectionDemo {
public static void main (String[] args) {
try {
Class cl = Class.forName("ClassesAndObjects.Student");
Method[] methods = cl.getMethods();
Field[] fields = cl.getFields();
System.out.println("The methods of the Student class are : ");
for (int i = 0 ; i < methods.length; i++) {
System.out.println(methods[i]);
}
System.out.println("The fields of the Student class are : ");
for (int i = 0 ; i < fields.length; i++) {
System.out.println(fields[i]);
}
}
catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
}
It does correctly output the Student class methods but it doesn't print the Student's class fields..
What am I missing here?
thanks