Skip to content

API to handle string constants #6

Description

@hyperpape

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions