Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » C-Sharp » Translation of <?> in .NET
Translation of <?> in .NET [message #566497] Thu, 18 September 2008 09:35
Alex FAU is currently offline Alex FAUFriend
Messages: 15
Registered: May 2010
Junior Member
(I re-post here a message from a list in Sourceforge)

In the current version of the translator I only support ot when it's a
parameter of a method :
public void method(List<?> list) --> public void Method<T>(List<T> list)
where T : class
public void method(List<? extends Object> list) --> public void
Method<T>(List<T> list) where T : class
public void method(List<? extends OtherType> list) --> public void
Method<T>(List<T> list) where T : OtherType
As you see I translate it into a generic method with constraint.
If you use <?> in a body I don'y modify it and the resulting buffer does
not compile in Visual Studio.

1/ List<?> myList = ...;
My point on this usage is :
If ? stand for "java.lang.Object" -> use the non generic version of list
instead (at least if you want to make your code translatable). BTW, it's
very frequent to see "Hashtable<String, ?>".
Otherwise ... do you really need to create a collection of you don't know
what ???
I mean the code I see frequently is :
List<?> myList = getList();
for(Object item : myList) {
SomeType myTypedItem = (SomeType) item;
...
}
And here the generics are useless ...

2/ List<? extends SomeType> myList = ...;
Ok that one is more "legitim" and I have no way to translate it in C#.
So, is it possible to introduce a generic parameter to the method/the
class that contains the statement in order to put the constraint on that
parameter and rewrite the list List<MyParameter> ?

Any ideas ? Comments ?
Previous Topic:Java2CSharp project nature
Next Topic:Translation of <?> in .NET
Goto Forum:
  


Current Time: Thu Mar 28 18:15:42 GMT 2024

Powered by FUDForum. Page generated in 0.03523 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top