Class does not compile when using the new java 8 Feature 'Optional'

Asked

Viewed 100 times

3

Good afternoon

I’m using play 2.5.4 with java 8 V01.08.91 And when using some java 8 Features as the 'Optional' class with ifPresent, isPresent or get methods the following error is displayed when compiling java classes

"java.lang.ClassCastException: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo"

Specifically, this is the excerpt from the code that the problem:

Optional<AppMobileWrapper> lastSend = appsWrapper.stream()
            .max(Comparator.comparing(f -> f.changeDate));

    lastSend.ifPresent(appMobileWrapper -> {
        returnWrapper.lastDate = DateUtils.currentDateNoTimeZoneString(appMobileWrapper.changeDate);
    });

I’ve tried everything, I’m hours away looking for a solution. My play version is up-to-date, updated java version, environment variables are ok and I even tried to add the updated javassist dependency to sbt dependencies and it still doesn’t work at all. Someone went through this trouble?

1 answer

1

After an upgrade in play/java, I solved similar problem by following the described instructions on this project project. In my case, I updated the javassist in project/plugins.sbt:

libraryDependencies += "org.javassist" % "javassist" % "3.20.0-GA"

Since the same would be used by a sbt plugin at build time and not in Runtime.

  • I already tried that, and it didn’t solve ;/

  • i added "org.javassist" % "javassist" % "3.20.0-GA" to my plugins.sbt and it worked. But really I didn’t understand the difference to what I already do, today I have a file .scala separated with all the dependencies of my project, I care in my build sbt. and concentrate on building the projects, and that didn’t work when I added the javassist.&#Can you explain to me the difference between plugins.sbt pro build sbt.?

  • @Rodrigowippel sees this as a schizophrenia of sbt :) project/plugins.sbt is used to define the plugins and their dependencies. In my case (and it looks like yours too) the javassist would be a dependency of a sbt plugin used only at compile time. What I don’t understand is why we need to declare this dependency manually, since our project (declared in build.sbt) does not depend directly on it.

  • That’s right! Anyway, thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.