Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » C-Sharp » Translation of <?> in .NET
Translation of <?> in .NET [message #469322] Thu, 18 September 2008 09:35 Go to next message
Alexandre FAU is currently offline Alexandre FAUFriend
Messages: 17
Registered: July 2009
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 ?
Re: Translation of <?> in .NET [message #469333 is a reply to message #469322] Thu, 18 September 2008 09:38 Go to previous message
Alexandre FAU is currently offline Alexandre FAUFriend
Messages: 17
Registered: July 2009
Junior Member
(readable version)

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).

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 ?
Re: Translation of <?> in .NET [message #566510 is a reply to message #469322] Thu, 18 September 2008 09:38 Go to previous message
Alexandre FAU is currently offline Alexandre FAUFriend
Messages: 17
Registered: July 2009
Junior Member
(readable version)

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).

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:Translation of <?> in .NET
Next Topic:No viable solution
Goto Forum:
  


Current Time: Mon Dec 22 13:01:36 GMT 2014

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

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