Generics and methods implementation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruno Neves Pires Silva

    Generics and methods implementation

    Hello, Programmers.

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

    class ClassName<typen ame>
    {
    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.
  • Peter Duniho

    #2
    Re: Generics and methods implementation

    On Fri, 06 Jun 2008 10:04:16 -0700, Bruno Neves Pires Silva
    <brunonpsilva@g mail.comwrote:
    I've got the following problem:I Have a class that uses generics like
    above:
    >
    class ClassName<typen ame>
    {
    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

    Comment

    Working...