Type mismatch in implicit conversion

Yes, I did already install it, but didn’t configure it properly yet. There are several Scala Extensions for VSCode. Shall I install Scala Syntax (official) and Scala (Metals)? Or only Scala (Metals)? Also, Metals complained that it could not find Java, although I have Java 14 on my Manjaro Linux. I entered the path to Java in Metals’ configurations manually and hope it will work. It says

Optional path to the Java home directory. Requires reloading the window.
Defaults to the most recent Java version between 8 and 11 (inclusive) computed by the locate-java-home npm package.

I have set $JAVA_HOME properly, but to Java 14, perhaps that’s the problem. Why does it only recognize Java up to version 11?

PS: I have reached the maximum number of posts for a new user on their first day… I think I will manage to configure Metals from here on. Thank you.

I have both and I believe you need both. Since the first one is just the syntax highlight, whereas the second one is the build server.

Also, Metals complained that it could find Java, although I have Java 14 on my Manjaro Linux.

Do you have your JAVA_HOME env var properly installed?
BTW, Java 14 is somewhat experimental and I would not use it with Scala, I would recommend you to use Java 8 or Java 11.
How did you install Java? The best way IMHO is to use sdkman (which will manage that env var for you).

If you got problems with your setup I would recommend you to ask in gitter the chat is more in real-time so it would be easier to help you.


Bear with me, the getting started is the worst part of the Scala experience, many people are working in making it easier. Since there everything will be better and great :slight_smile:

@BalmungSan provides one example, but more generally, there is a strong sentiment in Scala that Stronger Types Are Better, almost always. The => Any approach is very much the traditional Java way of doing things; Scala idiom is to favor maintaining the actual type whenever possible, to allow strongly-typed functions, and especially to enable typeclasses to do their job. As soon as you lose the actual type, you generally lose the ability to use typeclasses with your code, so it’s worth putting some effort into keeping the type whenever that is feasible – it often pays off downstream.

(The reasons why this matters will become a lot more obvious as you dive into Cats, since almost everything there is typeclass-centric. If you don’t keep your types, it becomes very hard to do much with it…)

1 Like

FWIW the compiler can issue a warning about this type of thing but it doesn’t do so by default. You have to enable the -Xlint:implicit-recursion compiler flag. In older versions either -Wself-implicit or -Ywarn-self-implicit.

implicit def Int2Boolean(x: Int): Boolean = x + 1
                                              ^
warning: Implicit resolves to enclosing method Int2Boolean
2 Likes