npryce / maybe-java

A Maybe type for Java
http://www.growing-object-oriented-software.com
Apache License 2.0
70 stars 18 forks source link

Type mismatch #5

Open orblivion opened 10 years ago

orblivion commented 10 years ago

I'm just trying this out, still novice in Java. I'm putting this in an Android project. I initially tried importing this as a project and I didn't immediately get it to work, so I just opted to import the library .jars and the source java.

I put the google collections jar in my /libs folder (I also tried with the latest guava, and I'm going to go with that ultimately if I can; same error here). I put Maybe.java in my /src directory.

So I get one error I don't understand: Type mismatch: cannot convert from Maybe<captrure#2-of ? extends U> to Maybe<U>

This is for the function: public <U> Maybe<U> to(Function<? super T, ? extends U> mapping).

For now I can just comment out that function, from your tutorial it sounded like it wasn't critical. But it seems cool so it'd be nice to have.

orblivion commented 10 years ago

I got the error to turn into a warning. I cast it in the return statement:

return (Maybe <U>) definitely(mapping.apply(theValue));

This gives the warning: 'Type safety: Unchecked cast from Maybe<capture#2-of ? extends U> to Maybe`

Still doesn't sound great.