It is possible write a method in java with generic class with argumet??
example:
public void Transfer (class c){ class.Search(); } It is possible write a method in java with generic class with argumet??
example:
public void Transfer (class c){ class.Search(); } Yes, you would need to do something like so:
public class Foo<T> { public void Transfer(T c) { c.Search(); } } Since you seem to want to invoke a specific method, you might want to define an interface which provides the methods you are after, and bind the generic constraint with it:
public interface MyInt { void Search(); } .... public class Foo<T extends MyInt> { public void Transfer(T c) { c.Search(); } } Alternatively:
public class Foo { public void Transfer(MyInt c) { c.Search(); } } The last example does away with generics and uses interfaces, which can sometimes yield code which is easier to follow, depending on what you are trying to achieve.