471,337 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Generics and methods implementation

Hello, Programmers.

I've got the following problem:I Have a class that uses generics like
above:

class ClassName<typename>
{
public void method(typename var)
{
var.Method2(); //I've got a error here.
}
}

How can I Access Method2 from the class typename ???

Thanks in advance.
Jun 27 '08 #1
1 997
On Fri, 06 Jun 2008 10:04:16 -0700, Bruno Neves Pires Silva
<br**********@gmail.comwrote:
I've got the following problem:I Have a class that uses generics like
above:

class ClassName<typename>
{
public void method(typename var)
{
var.Method2(); //I've got a error here.
}
}

How can I Access Method2 from the class typename ???
You need to include a constraint, or you need to cast the variable.

Note that if the type used as "typename" isn't an interface or a base
class for some other group of classes, then if you find yourself doing
this you may be negating the point of using a generic class. :)

Pete
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by andrew queisser | last post: by
13 posts views Thread by Anders Borum | last post: by
7 posts views Thread by Gene Vital | last post: by
3 posts views Thread by Showjumper | last post: by
7 posts views Thread by Ajeet | last post: by
13 posts views Thread by rkausch | last post: by
1 post views Thread by JosAH | last post: by
3 posts views Thread by =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.