This the code I’ve typed it and have problems with. I’ve included a copy of the original as well as what I’ve typed in.
This is the code I’ve typed in:
class Company( val name: String) {
private val departments: ArrayList = arrayListOf()
operator fun plusAssign(department: Department) {
departments.add(department)
}
operator fun minusAssign(department: Department) {
departments.remove(department)
}
val allEmployees: List
get() = arrayListOf().apply { departments.forEach{ addAll(it.employees)} }
}
This is the code that is a copy of the original:
class Company(val name: String) {
private val departments: ArrayList = arrayListOf()
val allEmployees: List
get() = arrayListOf().apply {
departments.forEach { addAll(it.employees) }
sort()
}
operator fun plusAssign(department: Department) {
departments.add(department)
}
operator fun minusAssign(department: Department) {
departments.remove(department)
}
}
The problem I’ve having problem with is the line that declares get() property for the company class. The look exactly the same to me but I’m sure I’ve typed it in correctly, for some reason I can’t type in sort() function. IntellijIDEA does not recognise it.
class Company( val name: String) {
private val departments: ArrayList<Department> = arrayListOf()
operator fun plusAssign(department: Department) {
departments.add(department)
}
operator fun minusAssign(department: Department) {
departments.remove(department)
}
val allEmployees: List<Employee>
get() = arrayListOf<Employee>().apply { departments.forEach { addAll(it.employees)} }
}
Here is the code that I downloaded:
Sorry, took me a few tries.
class Company(val name: String) {
private val departments: ArrayList<Department> = arrayListOf()
val allEmployees: List<Employee>
get() = arrayListOf<Employee>().apply {
departments.forEach { addAll(it.employees) }
sort()
}
operator fun plusAssign(department: Department) {
departments.add(department)
}
operator fun minusAssign(department: Department) {
departments.remove(department)
}
}