vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.59k stars 620 forks source link

Question about Seq interface (methods relates '? extends' type like groupBy ..etc) #2747

Closed usstwxy closed 1 year ago

usstwxy commented 1 year ago

I want to use vavr in my project with original java collections, and I feels the Seq seems to be a proper replacement of java.util.List since there are the common interface of linear ADT.

But I got some error in compile time when use Seq. For example:

class MyType { String id; int score; }
Seq<MyType> L = Vector.empty();
var m = L.groupBy(e -> e.id);
m.getOrElse("some_id", Vector.empty());

The last line would got a compile error that

Required type:
capture of ? extends Seq<MyType>

Provided:
Vector<java.lang.Object>

Event I try

Seq<MyType> empty = Vector.empty();
m.getOrElse("some_id", empty);

The similar error still exists.

It looks like the type ? extends Seq<MyType> is NOT compatible for Vector<MyType> or Seq<MyType>.

Question1: Is there a good method to resolve the type issue? Or we need to accept the fact? Question2: I also found that many of the Seq methods delcared with ? extends Seq<T>. If the ? extends Seq<T> is not good to use in Java, why not declare them just as Seq<T>?