Skip to content

Commit

Permalink
Change <? extends @nullable Object> back to <?>.
Browse files Browse the repository at this point in the history
(i.e., roll back the com.google.common part of cl/377083162)

The two should be equivalent, but Kotlin has/had a bug with `<?>` in the context of `@ElementTypesAreNonnullByDefault` (and/or `@ParametersAreNonnullByDefault`?).

Now that we're moving away from `@*AreNonnullByDefault` and onto `@NullMarked`, we can use the simpler version.

This is the next step toward [using JSpecify in Guava](jspecify/jspecify#239 (comment)).

PiperOrigin-RevId: 708605353
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 21, 2024
1 parent 8ebb375 commit 17634b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
25 changes: 7 additions & 18 deletions android/guava/src/com/google/common/base/Joiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,12 @@ private Joiner(Joiner prototype) {
this.separator = prototype.separator;
}

/*
* In this file, we use <? extends @Nullable Object> instead of <?> to work around a Kotlin bug
* (see b/189937072 until we file a bug against Kotlin itself). (The two should be equivalent, so
* we normally prefer the shorter one.)
*/

/**
* Appends the string representation of each of {@code parts}, using the previously configured
* separator between each, to {@code appendable}.
*/
@CanIgnoreReturnValue
public <A extends Appendable> A appendTo(A appendable, Iterable<? extends @Nullable Object> parts)
throws IOException {
public <A extends Appendable> A appendTo(A appendable, Iterable<?> parts) throws IOException {
return appendTo(appendable, parts.iterator());
}

Expand All @@ -109,8 +102,7 @@ public <A extends Appendable> A appendTo(A appendable, Iterable<? extends @Nulla
* @since 11.0
*/
@CanIgnoreReturnValue
public <A extends Appendable> A appendTo(A appendable, Iterator<? extends @Nullable Object> parts)
throws IOException {
public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException {
checkNotNull(appendable);
if (parts.hasNext()) {
appendable.append(toString(parts.next()));
Expand Down Expand Up @@ -151,8 +143,7 @@ public final <A extends Appendable> A appendTo(
* Iterable)}, except that it does not throw {@link IOException}.
*/
@CanIgnoreReturnValue
public final StringBuilder appendTo(
StringBuilder builder, Iterable<? extends @Nullable Object> parts) {
public final StringBuilder appendTo(StringBuilder builder, Iterable<?> parts) {
return appendTo(builder, parts.iterator());
}

Expand All @@ -164,8 +155,7 @@ public final StringBuilder appendTo(
* @since 11.0
*/
@CanIgnoreReturnValue
public final StringBuilder appendTo(
StringBuilder builder, Iterator<? extends @Nullable Object> parts) {
public final StringBuilder appendTo(StringBuilder builder, Iterator<?> parts) {
try {
appendTo((Appendable) builder, parts);
} catch (IOException impossible) {
Expand Down Expand Up @@ -204,7 +194,7 @@ public final StringBuilder appendTo(
* Returns a string containing the string representation of each of {@code parts}, using the
* previously configured separator between each.
*/
public String join(Iterable<? extends @Nullable Object> parts) {
public String join(Iterable<?> parts) {
// We don't use the same optimization here as in the JRE flavor.
// TODO: b/381289911 - Evaluate the performance impact of doing so.
return join(parts.iterator());
Expand All @@ -224,7 +214,7 @@ public String join(Iterable<? extends @Nullable Object> parts) {
*
* @since 11.0
*/
public final String join(Iterator<? extends @Nullable Object> parts) {
public final String join(Iterator<?> parts) {
return appendTo(new StringBuilder(), parts).toString();
}

Expand Down Expand Up @@ -284,8 +274,7 @@ public String join(Iterable<? extends @Nullable Object> parts) {
}

@Override
public <A extends Appendable> A appendTo(
A appendable, Iterator<? extends @Nullable Object> parts) throws IOException {
public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException {
checkNotNull(appendable, "appendable");
checkNotNull(parts, "parts");
while (parts.hasNext()) {
Expand Down
25 changes: 7 additions & 18 deletions guava/src/com/google/common/base/Joiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,12 @@ private Joiner(Joiner prototype) {
this.separator = prototype.separator;
}

/*
* In this file, we use <? extends @Nullable Object> instead of <?> to work around a Kotlin bug
* (see b/189937072 until we file a bug against Kotlin itself). (The two should be equivalent, so
* we normally prefer the shorter one.)
*/

/**
* Appends the string representation of each of {@code parts}, using the previously configured
* separator between each, to {@code appendable}.
*/
@CanIgnoreReturnValue
public <A extends Appendable> A appendTo(A appendable, Iterable<? extends @Nullable Object> parts)
throws IOException {
public <A extends Appendable> A appendTo(A appendable, Iterable<?> parts) throws IOException {
return appendTo(appendable, parts.iterator());
}

Expand All @@ -109,8 +102,7 @@ public <A extends Appendable> A appendTo(A appendable, Iterable<? extends @Nulla
* @since 11.0
*/
@CanIgnoreReturnValue
public <A extends Appendable> A appendTo(A appendable, Iterator<? extends @Nullable Object> parts)
throws IOException {
public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException {
checkNotNull(appendable);
if (parts.hasNext()) {
appendable.append(toString(parts.next()));
Expand Down Expand Up @@ -151,8 +143,7 @@ public final <A extends Appendable> A appendTo(
* Iterable)}, except that it does not throw {@link IOException}.
*/
@CanIgnoreReturnValue
public final StringBuilder appendTo(
StringBuilder builder, Iterable<? extends @Nullable Object> parts) {
public final StringBuilder appendTo(StringBuilder builder, Iterable<?> parts) {
return appendTo(builder, parts.iterator());
}

Expand All @@ -164,8 +155,7 @@ public final StringBuilder appendTo(
* @since 11.0
*/
@CanIgnoreReturnValue
public final StringBuilder appendTo(
StringBuilder builder, Iterator<? extends @Nullable Object> parts) {
public final StringBuilder appendTo(StringBuilder builder, Iterator<?> parts) {
try {
appendTo((Appendable) builder, parts);
} catch (IOException impossible) {
Expand Down Expand Up @@ -204,7 +194,7 @@ public final StringBuilder appendTo(
* Returns a string containing the string representation of each of {@code parts}, using the
* previously configured separator between each.
*/
public String join(Iterable<? extends @Nullable Object> parts) {
public String join(Iterable<?> parts) {
/*
* If we can quickly determine how many elements there are likely to be, then we can use the
* fastest possible implementation, which delegates to the array overload of String.join.
Expand Down Expand Up @@ -264,7 +254,7 @@ public String join(Iterable<? extends @Nullable Object> parts) {
*
* @since 11.0
*/
public final String join(Iterator<? extends @Nullable Object> parts) {
public final String join(Iterator<?> parts) {
return appendTo(new StringBuilder(), parts).toString();
}

Expand Down Expand Up @@ -324,8 +314,7 @@ public String join(Iterable<? extends @Nullable Object> parts) {
}

@Override
public <A extends Appendable> A appendTo(
A appendable, Iterator<? extends @Nullable Object> parts) throws IOException {
public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException {
checkNotNull(appendable, "appendable");
checkNotNull(parts, "parts");
while (parts.hasNext()) {
Expand Down

0 comments on commit 17634b5

Please sign in to comment.