Comments (7)
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)
from nbt.
public ListTag(Class<? super T> typeClass)
That should be ? extends T
, otherwise it would allow stuff like new ListTag(Object.class)
.
from nbt.
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);
java: incompatible types: cannot infer type arguments for net.querz.nbt.ListTag<>
reason: cannot infer type-variable(s) T
(argument mismatch; java.lang.Class<net.querz.nbt.ListTag> cannot be converted to java.lang.Class<? extends net.querz.nbt.ListTag<?>>)
Also, this restricts the type of the class to be exactly the type of the ListTag, even though the definition is kinda verbose.
from nbt.
which in turn must be a subclass of Tag<?>
Where is this restriction?
I am not getting any compilation problems when changing the constructor parameter.
from nbt.
Where is this restriction?
In the class definition:
public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<T> {
I am not getting any compilation problems when changing the constructor parameter.
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 Class<? extends T>
:
[...]\NBT\src\test\java\net\querz\nbt\ListTagTest.java:242: error: incompatible types: cannot infer type arguments for ListTag<>
ListTag<ListTag<?>> recursive = new ListTag<>(ListTag.class);
^
reason: cannot infer type-variable(s) T
(argument mismatch; Class<ListTag> cannot be converted to Class<? extends ListTag<?>>)
where T is a type-variable:
T extends Tag<?> declared in class ListTag
from nbt.
Removed all raw types.
The constructor of ListTag now takes a class of type ? super T
while T extends Tag<?>
, which restricts the class to be the exact same type as T but still allows a ListTag of type ListTag<?>
:
ListTag<ListTag<?>> l = new ListTag<>(ListTag.class);
from nbt.
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 javac
did not.
Here is the minimal test code, which should fail compiling for you:
public class ClassTest<T> {
public ClassTest(Class<? extends T> classArg) { }
public static void testNested() {
// Compiles with Eclipse, but not with standard JDK
ClassTest<ClassTest<?>> nested = new ClassTest<>(ClassTest.class);
}
}
Hopefully I find the respective Eclipse bug report or get around to reporting it at some point.
from nbt.
Related Issues (20)
- This repo doesnt write valid NBT for MCA HOT 1
- Populating a new chunk from scratch results in an ArrayIndexOutOfBoundsException HOT 4
- Please merge the little-endian-io-SNAPSHOT branch over the recommended public branch(es) HOT 1
- Limited height on write region file
- Upload releases to maven central HOT 1
- Update README
- Strings with the literal values "true" and "false" are mistaken with bytes when written and parsed from SNBT. HOT 1
- Charset problem while recreating Minecraft servers.dat file HOT 1
- StringOutOfBoundsIndexException issue, and ParseException suggestion
- Suggestion: Block State Parser
- Cast exception while reading mca file
- How do I serialize an NBT compound?
- 1.18 Support? HOT 3
- ListTag Double issue HOT 1
- .0 is ignored in doubles in toSNBT
- "cannot cast ListTag<ByteTag> to ListTag<CompoundTag>" when open Entities tag HOT 1
- Support for POI mca files?
- CompoundTag .get method returning null with valid key
- GZIP streams are not closed, causing errors when extracting.
- data does not contain Level tag fix HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbt.