Jump to content

  • Log In with Google      Sign In   
  • Create Account

Generics extends my baseclass can I use my baseclass functions?


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1   Members   

279
Like
0Likes
Like

Posted 30 November 2013 - 09:12 AM

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?

 



#2   Moderators   

10730
Like
0Likes
Like

Posted 30 November 2013 - 12:13 PM

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()).






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.