Skip to content

Id conflict for AttributeKey<T> with different types #498

@yyjdelete

Description

@yyjdelete

Unlike java, which does generic type erase; AttributeKey<Class1> and AttributeKey<Class2> are 2 different types in dotnet, that mean they will use 2 separate AttributeConstantPool, and can both the same Id.

That will make DefaultAttributeMap inefficient(still work, just inefficient)
, because it always use bucket-1, and never use 0,2,3 when you use more than 1 AttributeKey<T> and always with different types.

Maybe AttributeKey<T> needed to be separated to 2 types(like System.Tuple and System.Tuple<T1,...>), use an new utils class static class AttributeKey to hold all static methods and fields(or just fields for binary compatibility), and use the old sealed class AttributeKey<T> : AbstractConstant<AttributeKey<T>> for the data class itself.

***NOTE: *** It's always not safe for binary compatibility, since AttributeKey<T>.Pool is an public static field, and may be used by libs.
Can be marked as Obsolete and set AttributeKey<T>.Pool = AttributeKey.Pool

public sealed class AttributeKey<T> : AbstractConstant<AttributeKey<T>>
{
public static readonly ConstantPool Pool = new AttributeConstantPool();

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