0

I am new to Scala, so please bear any bloopers in my code. I'm trying to re-engineer some Scala code that has been given to me. When I'm trying to use Java inheritance, I get type mismatch; found error highlighted in eclipse.

I'm using sbt to generate eclipse artifacts and I'm able to import the project in eclipse.The code with the error is given below.

The interface:

public interface InnerClassGen {

    static public interface IFactory {
      InnerInter innerInt = null;
      /** A String giving the canonical value of symbol. */
        //@ pure
        Integer value();
        @Override
        String toString();
    }
}

public class InnerClassImpl implements InnerClassGen {

   static public class Node implements IFactory{

      @Override
      public Integer value() {
        // TODO Auto-generated method stub
        return null;
      }
   }
}

The relevant Scala file :

object SMTExprVisitor {
   protected var NODE: InnerClassGen.IFactory = new InnerClassImpl.Node()
}

class SMTExprVisitor{
.....
}

I would like to know where I'm going wrong. Can someone also point me to relevant links if any?

Puneeth Reddy V
  • 1,538
  • 13
  • 28
George
  • 15
  • 7
  • 6
    What is the error text (always post it when asking about compilation errors!)? Does it post exactly to the `var NODE` line? Does the error happen when compiling in SBT or only in the IDE? – Alexey Romanov Jan 31 '19 at 13:03
  • I'm able to compile the code in sbt. Only Eclipse highlights the code as error - should have made it clear. The exact error text in Eclipse is "type mismatch; found : InnerClassImpl.Node required: InnerClassGen.IFactory. – George Feb 01 '19 at 12:11
  • This means you aren't going wrong anywhere, and the code works. It should just be reported as a Scala IDE bug (after checking it hasn't been already). – Alexey Romanov Feb 01 '19 at 12:19

1 Answers1

1

In general, you should always consider only compilation errors produced by SBT (or scalac directly) as real ones. Due to complexity of the language, and limited integration with the compiler, Scala IDEs can both highlight code as having errors when it doesn't and fail to find errors which do exist.

Though Eclipse is supposed to be better at this than IDEA/Android Studio due to using the "presentation compiler" which extends the main Scala compiler, apparently you are still running into a case it doesn't handle.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487