Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

java higher-kind interop fails with dotty #16797

Discussion options

let's consider the following scala code

trait HigherKind[C[_]]

And java one

public class JHigherKindWrapper {
 private HigherKind<java.util.List> underlying;
}

This used to compile with scala 2.12 and 2.13. With scala 3.2.1, the compiler fails with the following:

[error] | private HigherKind<java.util.List> underlying;
[error] | ^^^^^^^^^^^^^^
[error] |Type argument java.util.List[?] does not have the same kind as its bound [_1ドル]

Why is dotty failing compilation in this case ?
I've setup a minimal project to reproduce here.

You must be logged in to vote

Java doesn't have higher-kinded types: while you can write java.util.List without passing type arguments to it, it is equivalent to java.util.List<?> (it's a raw type). When compiling a mixed java/scala project, the Scala compiler also typechecks Java sources, so it will error out on HigkerKind<java.util.List> which it will interpret as the Scala type HigherKind[java.util.List[?]].

I'm not sure why it doesn't happen in Scala 2 though. What's your usecase? If the Scala code doesn't depend on the Java code, you could set up your build tool so the Scala compiler doesn't see the Java code at all (in sbt: compileOrder := CompileOrder.ScalaThenJava)

Replies: 1 comment 1 reply

Comment options

Java doesn't have higher-kinded types: while you can write java.util.List without passing type arguments to it, it is equivalent to java.util.List<?> (it's a raw type). When compiling a mixed java/scala project, the Scala compiler also typechecks Java sources, so it will error out on HigkerKind<java.util.List> which it will interpret as the Scala type HigherKind[java.util.List[?]].

I'm not sure why it doesn't happen in Scala 2 though. What's your usecase? If the Scala code doesn't depend on the Java code, you could set up your build tool so the Scala compiler doesn't see the Java code at all (in sbt: compileOrder := CompileOrder.ScalaThenJava)

You must be logged in to vote
1 reply
Comment options

Thanks a lot. Changing the compile order worked!

Answer selected by RustedBones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /