> extends CCC{} ...">

"java wildcard" in C #?

How do I convert "java wildcards" to C # format?

public abstract class AAA<T extends BBB<?>> extends CCC<T>{} 

      

My wrong C # code

public abstract class AAA<T> : CCC<T> where T : BBB<?>{}

      

How to convert BBB<?>

+3


source to share


2 answers


There is a similar C # generic question "where is the constraint" with "any generic type" definition? does not apply to Java templates. The answer provided there will most likely help you.

From this answer, a possible class signature would be:

public abstract class AAA<T, TOther> : CCC<T>
    where T : BBB<TOther>
{}

      



Generics in C # must have named type parameters, even if you never plan on using that type explicitly / implicitly. And all type parameters must be named in the method / class / interface identifier declaration.

Note that it would be possible to restrict TOther to objects only if desired, using:

public abstract class AAA<T, TOther> : CCC<T>
    where T : BBB<TOther>
    where TOther : object
{}

      

+1


source


What is BBB

exactly?



I'm sure it BBB<Object>

will probably work; BBB

is probably a covariant type.

0


source







All Articles