Java syntax question: <O> O accept(ObjectVisitorEx<O> visitor)
-
10-07-2019 - |
Question
Naive question about Java syntax. What does
<T> T accept(ObjectVisitorEx<T> visitor);
mean? What would be the C# equivalent?
Solution
The C# equivalent would be more or less the same. If the visitor were an interface it would be
O Accept(IObjectVisitorEx<O> visitor);
OTHER TIPS
In C# it could be:
O Accept<O>(ObjectVisitorEx<O> visitor);
This is used for passing types as parameters. C# syntax is the same (<Type>). Suggest googling for term 'generics' as this is the term you're looking for.
Here's a good comparison between Java and C# generics.
see Java: http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
and C#: http://msdn.microsoft.com/en-us/library/ms379564(VS.80).aspx
A similar C# method could be
public T Foo<T>(Queue<T> v) // Queue<T> chosen for simplicity
{
return v.Dequeue();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow