Is there such a possibility? I create an attribute and I want a static instance to be returned when creating an instance (so that for each object to which the attribute is applied, a separate attribute instance is not created).

That is, in this case

[MyAttr] class MyClass{ } 

a new instance of MyAttrAttribute should not be created for a class, but instead an already created (static) one should be passed.

    1 answer 1

    No The constructor is the constructor that constructs the new object.

    Perhaps in your case, the decision will be to make the constructor private, and to create an object through a static method (or some other implementation of the Factory pattern).

    • private constructor does not allow the use of the attribute. It's a pity. Well, okay, get along. ( - iRumba
    • @iRumba: Well, yes, if this is an attribute, the trick will not work. - VladD