Samir Amanov
Samir Amanov

Reputation: 169

How can I change enum values?

I have imported org.jsmpp, which has enum class StringParameter. How can I change values of enum, in my class?

StringParameter class:

public enum StringParameter {

SERVICE_TYPE(StringType.C_OCTET_STRING, 0, 6, true, SMPPConstant.STAT_ESME_RINVSERTYP);

private StringType type;
private final int min;
private final int max;
private final boolean rangeMinAndMax;
private final int errCode;


StringParameter(StringType type, int min, int max, boolean rangeMinAndMax, int errCode) {
    this.type = type;
    this.min = min;
    this.max = max;
    this.rangeMinAndMax = rangeMinAndMax;
    this.errCode = errCode;
}


public int getMax() {
    return max;
}


public int getMin() {
    return min;
}


public boolean isRangeMinAndMax() {
    return rangeMinAndMax;
}

public StringType getType() {
    return type;
}


public int getErrCode() {
    return errCode;
}

I want to change SERVICE_TYPE max from 6 to 12.

Upvotes: 0

Views: 785

Answers (1)

GhostCat
GhostCat

Reputation: 140417

Two cases here:

  • you really use import StringParameter somewhere in your code, and you included the corresponding class file(s) in your project setup. Then there is nothing you can do.
  • you copied the source code. Then theoretically, you could just go in and make changes to that source code (assuming that the licence model allows you to do that).

Otherwise, your hands are tied. Consider enums to be constants, there is no changing of values at runtime.

Note: you also can't extend that existing enum with your own version, as well, there is inheritance for enums. If at all, you would have to create your very own enum here.

Update: of course, when you use some external library, you can theoretically do two things:

  • you automate the process of downloading the JAR, unpacking it, manipulating that java enum (hopefully they provide the source code, and give you the right to do that), recompile, and repackage
  • maybe contact the people owning that library, maybe there is a way to patch that code in ways that work for everybody

Upvotes: 1

Related Questions