Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You can create an isValid or checkValid method inside the enum and override it in h3 if it's not changing runtime.

public enum TestEnum {
 h1, 
 h2, 
 h3 {
 @Override
 public boolean isValid() {
 return false;
 }
 },
 h4;
 public boolean isValid() {
 return true;
 }
}

It returns true for h1, h2 and h4, false for h3.

You could eliminate the results variable from checkExcept:

public static boolean checkExcept(String el, TestEnum... except) {
 try {
 return !Arrays.asList(except).contains(TestEnum.valueOf(el));
 } catch (Exception e) {
 return false;
 }
}

Please note that catching Exception is almost always a bad idea catching Exception is almost always a bad idea. I'd catch a more specific exception here (IllegalArgumentException).

You can create an isValid or checkValid method inside the enum and override it in h3 if it's not changing runtime.

public enum TestEnum {
 h1, 
 h2, 
 h3 {
 @Override
 public boolean isValid() {
 return false;
 }
 },
 h4;
 public boolean isValid() {
 return true;
 }
}

It returns true for h1, h2 and h4, false for h3.

You could eliminate the results variable from checkExcept:

public static boolean checkExcept(String el, TestEnum... except) {
 try {
 return !Arrays.asList(except).contains(TestEnum.valueOf(el));
 } catch (Exception e) {
 return false;
 }
}

Please note that catching Exception is almost always a bad idea. I'd catch a more specific exception here (IllegalArgumentException).

You can create an isValid or checkValid method inside the enum and override it in h3 if it's not changing runtime.

public enum TestEnum {
 h1, 
 h2, 
 h3 {
 @Override
 public boolean isValid() {
 return false;
 }
 },
 h4;
 public boolean isValid() {
 return true;
 }
}

It returns true for h1, h2 and h4, false for h3.

You could eliminate the results variable from checkExcept:

public static boolean checkExcept(String el, TestEnum... except) {
 try {
 return !Arrays.asList(except).contains(TestEnum.valueOf(el));
 } catch (Exception e) {
 return false;
 }
}

Please note that catching Exception is almost always a bad idea. I'd catch a more specific exception here (IllegalArgumentException).

Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157

You can create an isValid or checkValid method inside the enum and override it in h3 if it's not changing runtime.

public enum TestEnum {
 h1, 
 h2, 
 h3 {
 @Override
 public boolean isValid() {
 return false;
 }
 },
 h4;
 public boolean isValid() {
 return true;
 }
}

It returns true for h1, h2 and h4, false for h3.

You could eliminate the results variable from checkExcept:

public static boolean checkExcept(String el, TestEnum... except) {
 try {
 return !Arrays.asList(except).contains(TestEnum.valueOf(el));
 } catch (Exception e) {
 return false;
 }
}

Please note that catching Exception is almost always a bad idea. I'd catch a more specific exception here (IllegalArgumentException).

lang-java

AltStyle によって変換されたページ (->オリジナル) /