I’m having a problem using ArrayList in Scala . The code is below
import org.apache.flink.core.fs._ ….. } Scala refuses to recognise ArrayList. The IDE InteliJ likewise flags java.util as not existing, even though it recognises ArrayList and suggest auto-insertion of the import java.utils.ArrayList statement. The compilation errors are [error] ………………/src/main/scala/org/example/Job.scala:30:13: object util is not a member of package org.apache.flink.table.api.java [error] import java.util.ArrayList [error] ^ [error] ………………/src/main/scala/org/example/Job.scala:34:23: not found: type ArrayList [error] val httpHosts = new ArrayList[HttpHost] [error] ^ [error] two errors found [error] (Compile / compileIncremental) Compilation failed Without the ArrayList reference the code compiles with no errors. The sbt build file, if it helps is, resolvers in ThisBuild ++= Seq("Apache Development Snapshot Repository" at "https://repository.apache.org/content/repositories/snapshots/", Resolver.mavenLocal) name := "Flink MultiChannel Project" version := "0.1-SNAPSHOT" organization := "org.example" scalaVersion in ThisBuild := "2.11.0" val flinkVersion = "1.8.1" val flinkDependencies = Seq( "org.apache.flink" %% "flink-scala" % flinkVersion , "org.apache.flink" %% "flink-table" % "1.7.2" , "org.apache.flink" %% "flink-connector-elasticsearch" % flinkVersion, "org.apache.flink" %% "flink-streaming-scala" % flinkVersion, "org.apache.httpcomponents" % "httpclient" % "4.5.10", "org.apache.httpcomponents" % "httpcore" % "4.4.11") lazy val root = (project in file(".")). settings( libraryDependencies ++= flinkDependencies) mainClass in assembly := Some("org.example.Job") // make run command include the provided dependencies run in Compile := Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run)) // exclude Scala library from assembly assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false) TIA Nick
|
I’ve shrunk the problem down to a minimal size. The code
package org.example will not compile, but remove the import org.apache.flink.table.api._ and all is well Nick
|
Hi Nick,
The error message shows that it tries to find "util.ArrayList" under package "org.apache.flink.table.api.java". So you can try one of the following two solutions: 1) Don't import "org.apache.flink.table.api._" 2) Use absolute import: "import _root_.java.util.ArrayList" Regards, Dian
|
Dian
That fixed the problem thanks you. It would appear that someone has taken it upon themselves to redefine part of the Java standard library in org.apache.flink.table.api._ NIck
|
Hi Nick, There is a package named "org.apache.flink.table.api.java" in flink and so the import of "org.apache.flink.table.api._" causes "org.apache.flink.table.api.java" imported. Then all the import of package starting with "java" such as "import java.util.ArrayList" will try to find the classes under "org.apache.flink.table.api.java" as Scala uses relative import by default. So I think nothing is wrong here. This is the behavior of Scala language. You just need to use prefix of "_root_" to force using absolute import. Regards, Dian
|
Hi Dian, What about rename api.java to japi if there is no unexpected compatibility issue? I think we can always avoid use a `.java.` in package names. Best, tison. Dian Fu <[hidden email]> 于2019年9月26日周四 下午10:54写道:
|
Hi tison, Actually there may be compatibility issues as the BatchTableEnvironment/StreamTableEnvironment under "api.java" are public interfaces. Regards, Dian
|
Thanks for your information Dian. It is not an urgent issue though. Maybe revisit later :-) Best, tison. Dian Fu <[hidden email]> 于2019年9月30日周一 下午7:34写道:
|
Free forum by Nabble | Edit this page |