Below is the code I am trying to run:
class Student {
def printDetails = println("I am a student")
def printSomeOtherDetails = println("I love Studying")
}
class ComputerScienceStudent extends Student {
override def printDetails = println("I am a Computer Science Student")
override def printSomeOtherDetails = println("I love Scala")
}
class InformationTechnologyStudent extends Student {
override def printDetails = println("I am an Information Technology Student")
override def printSomeOtherDetails = println("I love Java")
}
class MyGenericClassForUpperBound {
def printStudentDetails[S <: Student](student: S) = {
student.printDetails
student.printSomeOtherDetails
}
}
class MyGenericClassforLowerBound {
def printStudentDetails[S >: ComputerScienceStudent](student: S) = {
student.printDetails
student.printSomeOtherDetails
}
}
the method printStudentDetails
from MyGenericClassforLowerBound
is creating the problem. The statements student.printDetails
and student.printSomeOtherDetails
are telling me
value printDetails is not a member of type parameter S
As far as I understood:
Q[A <: B]
means the class/methodQ
can take any objects of classA
where ClassA
is the sub type of classB
. This is called Upper Bound.Q[A >: B]
means the class/methodQ
can take any objects of classA
where ClassA
is the super type of classB
. This is called Lower Bound.
Please help me if my understanding is wrong and help me to understand why the above stated problem is coming. Thanks guys.