Conceito Scala UpperBound e LowerBound
Abaixo está o código que estou tentando executar:
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
}
}
o métodoprintStudentDetails
deMyGenericClassforLowerBound
está criando o problema. As declaraçõesstudent.printDetails
estudent.printSomeOtherDetails
está me dizendo
value printDetails is not a member of type parameter S
Tanto quanto eu entendi:
Q[A <: B]
significa a classe / métodoQ
pode pegar qualquer objeto de classeA
onde a classeA
é o subtipo de classeB
. Isso é chamado de limite superior.Q[A >: B]
significa a classe / métodoQ
pode pegar qualquer objeto de classeA
onde a classeA
é o tipo super de classeB
. Isso é chamado de limite inferior.Por favor, ajude-me se meu entendimento estiver errado e me ajude a entender por que o problema acima está vindo. Obrigado rapazes.