FlyingGuy
FlyingGuy

Reputation: 333

Java pass object of any class as a parameter

So the idea is...

In C and in other languages you can pass an untyped pointer as a parameter, e.g.:

C

foo( void* p1 ) ;

pascal

function foo(pointer p1 ) : string ;

These are untyped and it is on the function to know what to do with them. I want to do the same thing in java e.g.:

class some class{

   String someMethod(Class p1){
      return (String) p1
   }

}

Is this even possible?

Upvotes: 0

Views: 2072

Answers (1)

user2357112
user2357112

Reputation: 282035

You want Object, not Class.

public String someMethod(Object p1) {
    return whatever;
}

Upvotes: 3

Related Questions