Generics extends my baseclass can I use my baseclass functions?

Started by
0 comments, last by rip-off 10 years, 4 months ago

Hi

I was wondering if it possible to reach my baseclass functionality


public <T extends BaseComponent> T getComponent(Class<T> type)
	{
		for(int i = 0;i < this.componentList.size();i++)
		{
			if(this.componentList.get(i).typeName.equals(     
                                                                      type.typeName() 
                                                                     ))
			{
				return type.cast(this.componentList.get(i));
			}	
		}
		return null;
	}

in my BaseComponent I have a public string, is it possible to access it from the template?

my base class is also a abstract class if that matter?

Advertisement

You can use type.isInstance() followed by type.cast(). I'm not sure "typeName" is actually necessary, it would appear to be duplicating Java's built-in reflection (object.getClass()).

This topic is closed to new replies.

Advertisement