-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Excessive usage of raw types #20
Comments
I see your point and i'm working on it. There is one Problem creating a ListTag of ListTags. Based on how you create ListTags using the constructor that takes the type class, it would be intuitive to do it this way: ListTag<ListTag<?>> l = new ListTag<>(ListTag.class); But obviously this doesn't compile because ListTag.class is not of type ListTag<?>. And something like the following would be really ugly and having users of this library do this would be unreasonable: ListTag<ListTag<?>> l = new ListTag<>((Class<ListTag<?>>)((Class<?>)ListTag.class)); Edit: Nevermind, i'm stupid. I can just modify the Constructor to accept a class of any type extending T public ListTag(Class<? super T> typeClass) |
That should be |
I am allowing the type of the class to be a superclass of T, which in turn must be a subclass of Tag<?> (Tag of any type), therefore the type of the class can't be a supertype of the ListTag's type. If i restrict the type of the class to be a subclass of T instead, i have trouble creating a ListTag of ListTags: ListTag<ListTag<?>> l = new ListTag<>(ListTag.class);
Also, this restricts the type of the class to be exactly the type of the ListTag, even though the definition is kinda verbose. |
I am not getting any compilation problems when changing the constructor parameter. |
In the class definition: public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<T> {
Weird... I'm using Intellij IDEA 2018.2 to compile with JDK 1.8.0_181 and the unit tests won't compile with this error when i change the constructor parameter to
|
Removed all raw types. ListTag<ListTag<?>> l = new ListTag<>(ListTag.class); |
Sorry that I have not said it before, but thanks for putting all this work into this project! To the compiling problem again, it looks like it is working for me because I use Eclipse which uses its own compiler. There have been other cases where Eclipse compiled code just fine, but Here is the minimal test code, which should fail compiling for you:
Hopefully I find the respective Eclipse bug report or get around to reporting it at some point. |
Often generic types such as
Tag
do not have the type parameters specified (i.e. raw type), even in recent commits.Raw types can become pretty dangerous, see this StackOverflow answer for a good explanation.
The text was updated successfully, but these errors were encountered: