https://kotlinlang.org logo
#announcements
Title
# announcements
p

pniederw

09/14/2017, 9:33 AM
still hoping for an answer: is this compile error expected, and if so, what’s the rationale?
Copy code
class Outer {
  sealed class Foo {}
  
  // cannot access '<init>': it is private in 'Foo'
  class Bar : Foo() {}
}
o

orangy

09/14/2017, 9:35 AM
@stanislav.erokhin
n

nil2l

09/14/2017, 9:39 AM
Maybe it is as rules changed in 1.1?
Copy code
A sealed class can have subclasses, but all of them must be declared in the same file as the sealed class itself. (Before Kotlin 1.1, the rules were even more strict: classes had to be nested inside the declaration of the sealed class).
p

pniederw

09/14/2017, 9:40 AM
what do you mean by “it is as rules changed”?
it is expected?
n

nil2l

09/14/2017, 9:41 AM
I mean before 1.1 you could declare it as inner class. After — only as few classes in one file (and not as inner classes).
p

pniederw

09/14/2017, 9:41 AM
1.1 lifted some restrictions, it didn’t add any
but apparently the enhancements in 1.1 don’t extend to the nested class case. I wonder if they should.
n

nil2l

09/14/2017, 9:43 AM
Isn’t this a restriction?
Copy code
all of them _must_ be declared in the same file as the sealed class itself
p

pniederw

09/14/2017, 9:43 AM
no
(not compared to 1.0)
s

stanislav.erokhin

09/14/2017, 9:44 AM
It is expected behaviour for now. In 1.0 subclasses for sealed classes was allowed only inside corresponding class, and in 1.1 we allow top-level subclasses for top-level sealed classes. We can support such cases later.
3 Views