Skip to content

Instantly share code, notes, and snippets.

@jnizet
Created February 15, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnizet/7f7ca3cac338ae15c0b7ce721b25f230 to your computer and use it in GitHub Desktop.
Save jnizet/7f7ca3cac338ae15c0b7ce721b25f230 to your computer and use it in GitHub Desktop.
data class Course(val id: Long, val students: MutableSet<Student> = mutableSetOf())
data class Student(val id: Long, val courses: MutableSet<Course> = mutableSetOf())
fun main() {
val english = Course(1L)
val john = Student(1L)
english.students.add(john)
john.courses.add(english)
println(john) // StackOverflowError
println(english.students.contains(john)) // StackOverflowError
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment