My intent is to put the list of Tse
objects into Bts
object in Java:
Bts Object should contain List=
List(Tse(1285927200000,1285928100000,0.0),
Tse(1285928100000,1285929000000,1.0),
Tse(1285929000000,1285929900000,2.0),
Tse(1285929900000,1285930800000,3.0))
I have scala files Bts
, Ts
and Tse
:
Bts.scala
trait Bts extends Ts{
def start:Long
def end:Long
def timezone:TimeZone
}
Ts.scala
Object Ts { //Some methods }
trait Ts extends Iterator[Tse] {
//Some methods
}
Tse.scala
case class Tse(val start:Long, val end:Long, val value:Option[Double], val elapsed:Long) {
def this(start: java.lang.Long, end: java.lang.Long,
value: java.lang.Double) = {
this(start, end, Option(value), end-start)
}
//Some methods
}
So, in Java code, I want to make Bts
object such that it should contain the following:
List(Tse(1285927200000,1285928100000,0.0),
Tse(1285928100000,1285929000000,1.0),
Tse(1285929000000,1285929900000,2.0),
Tse(1285929900000,1285930800000,3.0))
My Java code to do so:
Tse tse1= new Tse(1285927200000L, 1285928100000L, 0.0);
Tse tse2 = new Tse(1285928100000L, 1285929000000L, 1.0);
Tse tse3= new Tse(1285929000000L, 1285929900000L, 2.0);
Tse tse4 = new Tse(1285929900000L, 1285930800000L, 3.0);
List<Tse> entryList = new ArrayList<Tse>();
entryList.add(tse1);
entryList.add(tse2);
entryList.add(tse3);
entryList.add(tse4);
Bts bts= (Bts) entryList; //exception
Tsr$ tsr= Tsr$.MODULE$;
tsr.mcall(bts);
As you see that last line is giving me exception:
Caused by: java.lang.ClassCastException: java.util.ArrayList
cannot be cast to com.testapp.people.user.Bts
UPDATE:
Tsr.scala
object Tsr {
def mcall(sourceData: Iterator[Tse]) : Bts = { //Other calls}
}
UPDATE:
I tried to create an abstract class in Bts
and then tried to access it from Java:
Added the following in Bts.scala:
abstract class Bs(buffer:Iterator[Tse]) extends Bts{
}
From java:
Iterator<Tse> iterator = entryList.iterator();
Bts bts= new Bs(scala.collection.JavaConversions$.MODULE$.
asScalaIterator(iterator)); //exception
Now I am getting compile time error as:
Cannot instantiate the type Bs