#How to force public static final access via Class?

1 messages · Page 1 of 1 (latest)

fossil saffron
#

Hello all,

I basically have some constants stored in a class, like ```java
public class TypeLists {
public static final HashMap<String, Supplier<Class>> simpleInitType = new HashMap<>(Map.of(

));

}

I want to disallow accessing those constants directly, aka instead of allowing `simpleInitType.get("foo")` I want to forcibly make it so you have to type `TypeLists.simpleInitType.get("foot")` instead.
Is that possible in a java way? And if not, is there some IntelliJ setting that can enforce this?
wicked coralBOT
#

This post has been reserved for your question.

Hey @fossil saffron! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

paper yarrow
restive raven
#

But you have to type TypeLists.simpleInitType.get("foot") to access it already.

#

The only exception is the code inside of TypeLists.

paper yarrow
#

import static exists

restive raven
#

Oh yeah, also that.

#

But blocking import static for some particular class sounds like an idea of someone who hates other people.

fossil saffron
fossil saffron
paper yarrow
#

java will enforce what you're wanting if there is ambiguity.

#

so if two classes have the same static fields then yes, they will need to qualify the class afaik

fossil saffron
#

I see

#

thanks anyway

wicked coralBOT
# fossil saffron thanks anyway

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.