Skip to content

Commit

Permalink
Exploit generic variance in package bytes yegor256#1533
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Mar 8, 2021
1 parent 55c4534 commit 96f1240
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/bytes/CheckedBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public final class CheckedBytes<E extends Exception> implements Bytes {
/**
* Function that wraps exception of {@link #origin} to the required type.
*/
private final Func<Exception, E> func;
private final Func<? super Exception, ? extends E> func;

/**
* Ctor.
* @param orig Origin bytes.
* @param fnc Function that wraps exceptions.
*/
public CheckedBytes(final Bytes orig, final Func<Exception, E> fnc) {
public CheckedBytes(final Bytes orig, final Func<? super Exception, ? extends E> fnc) {
this.origin = orig;
this.func = fnc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/bytes/UncheckedBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class UncheckedBytes implements Bytes {
/**
* Fallback.
*/
private final Func<Exception, byte[]> fallback;
private final Func<? super Exception, ? extends byte[]> fallback;

/**
* Ctor.
Expand All @@ -67,7 +67,7 @@ public UncheckedBytes(final Bytes bts) {
* @since 0.5
*/
public UncheckedBytes(final Bytes bts,
final Func<Exception, byte[]> fbk) {
final Func<? super Exception, ? extends byte[]> fbk) {
this.bytes = bts;
this.fallback = fbk;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/collection/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Collections, tests.
*
* @since 0.14
* @todo #1533:30min Continue to exploit variance for package
* org.cactoos.collection to ensure typing works as best as
* possible as it is explained in #1533 issue.
*/
package org.cactoos.collection;
8 changes: 4 additions & 4 deletions src/main/java/org/cactoos/scalar/Checked.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public final class Checked<T, E extends Exception> implements Scalar<T> {
/**
* Function that wraps exception.
*/
private final Func<Exception, E> func;
private final Func<? super Exception, ? extends E> func;

/**
* Original scalar.
*/
private final Scalar<T> origin;
private final Scalar<? extends T> origin;

/**
* Ctor.
* @param scalar Encapsulated scalar
* @param fnc Func that wraps exception
*/
public Checked(final Scalar<T> scalar,
final Func<Exception, E> fnc) {
public Checked(final Scalar<? extends T> scalar,
final Func<? super Exception, ? extends E> fnc) {
this.func = fnc;
this.origin = scalar;
}
Expand Down

0 comments on commit 96f1240

Please sign in to comment.