public class Class{
public void method(class a, class b){
//some stuff
}
}
What i want is that a
and b
can be instances of any class. Is this legal in java? Is there any way to do this?
Thanks.
Use Object. Any class in Java is a (direct or indirect) sub-class of Object.
public class MyClass {
public void method(Object a, Object b){
//some stuff
}
}
Oh, and don't use the class name "Class". It's already used in Java.
Your given code is not legal because class
is a keyword in java see JLS 3.9. Keywords
USe can use Object
class from JLS 4.3.2. The Class Object
The class Object is a superclass (§8.1.4) of all other classes.
Use following:
public class Class{
public void method(Object a, Object b){
//some stuff
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With