views:

98

answers:

5

Naive question about Java syntax. What does

<T> T accept(ObjectVisitorEx<T> visitor);

mean? What would be the C# equivalent?

A: 

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();
}

VolkerK
+1  A: 

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.

quosoo
+1  A: 

The C# equivalent would be more or less the same. If the visitor were an interface it would be

O Accept(IObjectVisitorEx<O> visitor);
AgileJon
Wouldn't you need to declare O somewhere?
Tom Hawtin - tackline
+1  A: 

Here's a good comparison between Java and C# generics.

Otávio Décio
nice link. Thanks.
Dervin Thunk
+2  A: 

In C# it could be:

O Accept<O>(ObjectVisitorEx<O> visitor);
bruno conde
what's the difference between adding Accept<O> and just Accept as the accepted answer?
Dervin Thunk
With @AgileJon's answer the class is generic. This way only the method is generic...
bruno conde
The original question does indeed ask about a generic method.
Tom Hawtin - tackline
(The difference would be more obvious if the two versions were put together (for instance by accepting this answer).)
Tom Hawtin - tackline
Can I accept two answers?
Dervin Thunk