Skip to content

Commit

Permalink
a little bit more typesafe
Browse files Browse the repository at this point in the history
  • Loading branch information
querdenker2k committed Feb 19, 2025
1 parent bde2164 commit 5eb31ff
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
return null;
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public State toOhState() {
}

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
public <T extends JRuleValue> T as(Class<T> target) {
throw new IllegalStateException("cannot cast");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public interface JRuleValue {

State toOhState();

JRuleValue as(Class<? extends JRuleValue> target);
<T extends JRuleValue> T as(Class<T> target);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public State toOhState() {
protected abstract Type getOhType();

@Override
public JRuleValue as(Class<? extends JRuleValue> target) {
return JRuleEventHandler.get().toValue(toOhState().as(JRuleEventHandler.mapJRuleToOhType(target)));
public <T extends JRuleValue> T as(Class<T> target) {
// noinspection unchecked
return (T) JRuleEventHandler.get().toValue(toOhState().as(JRuleEventHandler.mapJRuleToOhType(target)));
}
}

0 comments on commit 5eb31ff

Please sign in to comment.