I am new to Scala and wondering if I can somehow refactor this code using Scala's support for function literals, higher order functions etc
Because there is no relationship between a Competition and a Team, I don't see how this is possible. I guess I could add a trait to Competition and Team that would include the name property and it would then be possible.
Any other alternatives?
class CompetitionDao extends BaseDao[Competition]{
def retrieveAllCompetitionNames(): java.util.List[String] = {
val competitions: java.util.List[_ <: Competition] = getDao().queryForAll()
val competitionNames: java.util.List[String] = new ArrayList();
for (competition <- competitions) competitionNames.add(competition.name)
competitionNames
}
}
class TeamDao extends BaseDao[Team]{
def retrieveAllTeamNames(): java.util.List[String] = {
val teams: java.util.List[_ <: Team] = getDao().queryForAll()
val teamNames: java.util.List[String] = new ArrayList();
for (team <- teams) teamNames.add(team.name)
teamNames
}
}