0

I have this Java method which is used to compare data:

org.apache.commons.lang3.builder.Diff;

public void addChangedPositions(DiffrentResult diffrentResult , List<UpdatedPositionsData> updatedPositionsData) {
    for (Diff<?> diff : diffResult.getDiffs()) {
      UpdatedPositionsData updatedData = new UpdatedPositionsData();
      updatedData.setName(diff.getFieldName() == null ? null : diff.getFieldName());
      updatedData.setOldValue(diff.getLeft() == null ? null : diff.getLeft().toString());
      updatedData.setNewValue(diff.getRight() == null ? null : diff.getRight().toString());
      updatedPositionsData.add(updatedField);
    }    
  }
........

@Getter
@Setter
public class UpdatedPositionsData {

  private String name;
  private String oldValue;
  private String newValue;

}

With version 'org.apache.commons:commons-lang3:3.8.1' it's working fine. But when I switch to version implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' I get error for this line for (Diff<?> diff : diffResult.getDiffs()) {

I get error:

incompatible types: Object cannot be converted to Diff<?>

So I have:

Required type:
Object

Provided:
Diff
<?>

Do you know how I can fix this issue?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

0

I said in an answer to your other question, incompatible types: Object cannot be converted to Diff<?>, that this occurs if you use raw types.

Now I've done some checking, and DiffResult has changed. In version 3.8.1 it wasn't a generic class: https://javadoc.io/doc/org.apache.commons/commons-lang3/3.8.1/org/apache/commons/lang3/builder/DiffResult.html. It was Iterable<Diff<?>>, but it had no generic type of its own. In version 3.10, it became generic: https://javadoc.io/doc/org.apache.commons/commons-lang3/3.10/org/apache/commons/lang3/builder/DiffResult.html.

My previous answer also shows the solution: use DiffResult<?>.

Rob Spoor
  • 6,186
  • 1
  • 19
  • 20