Skip to content

Tree-Structure does not inherit generics #112

@Placeblock

Description

@Placeblock

This problem is linked to this issue.

I tried implementing Brigadier, but if i try to create my argumentbuilder structure there is an exception.
The problem is that the generic information of the CommandDispatcher isn't passed to the added child-argumentbuilder

You can simplify the problem to theese few lines of code:

public class Main {

    public static void main(String[] args) {
        Node.<String>node().addChild(
            Node.node().addChild(
                Node.node()
            )
        );
    }

    private static class Node<S> {
        public static <S> Node<S> node() {
            return new Node<>();
        }

        public Node<S> addChild(Node<S> node) {
            return this;
        }
    }
}

If i try to execute this i get a compiler error saying: error: incompatible types: Node<Object> cannot be converted to Node<String>
Its obvious that my child node doesn't get the generic Type S from the root node and i think it is because of type erasure.
I am using Java 17 and because brigadier is written in java 8 i changed my java version to 8 but it doesn't work too.

I just don't understand how it can work for all the other devs using brigadier, has somebody a solution for that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions