Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to handle string constants #6

Open
hyperpape opened this issue Sep 30, 2023 · 0 comments
Open

API to handle string constants #6

hyperpape opened this issue Sep 30, 2023 · 0 comments

Comments

@hyperpape
Copy link
Owner

hyperpape commented Sep 30, 2023

String constants are ubiquitous, and right now it requires significant ceremony to use them--you have to pass the constant from whatever method you're using from where you're computing it out to a static block where you initialize it.

It seems easy enough for the class builder to make this simpler. Could, for instance, have a method that can be called from anywhere, which handles setting up the constants, so that they can be used.

registerStringConstant("constantName", "someString");
set("x", getStatic("constantName", thisClassType, Type.of(String.class));

We could also support an api like:

set("x", stringConstant("constantName", "someString"));

Which could do much the same thing, but allow inline definition at the point of use. In this case, the stringConstant call would have a side-effect of registering the constant, and return a StaticFieldReference as if we'd called getStatic. The advantage would be that it's concise, but I'm not sure multiplying the ways to do things is worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant