Hello, Abstract Class vs. Interface: Except that i...
# getting-started
c
Hello, Abstract Class vs. Interface: Except that it can only inherit 1 class, is there anything else in the interface that abstract classes cannot? Thanks.
ł
In Java there is also SAM conversion (it is available in Kotlin 1.4 preview), which allows lambda expressions to be converted to instance of such interface
Abstract class can hold variable/value, interface can't (but you can generate getters and setters instead). Abstract class have constructor, interface don't,
c
Thanks @Łukasz Patro, but my question was "is there anything else in the interface that abstract classes cannot?" Your comment is the other way around.
ł
The first comment answers the question, the second was indeed unnecessary 🙂
c
@Łukasz Patro, Kotlin itself is a programming language. So, if let's not relate Java in this context, can you please explain your comment about SAM above in the Kotlin world only? Also, I suspect there should be more important things that interfaces can but abstract classes cannot. I am still waiting for more comments from our Kotlin gurus. Thanks
d
Your question is asked the wrong way around, interfaces are more limited then classes. Interfaces cannot store data (they can only have abstract properties), interfaces cannot inherit from classes, interfaces cannot be instantiated, etc.
c
Thanks @diesieben07, so are you saying that there is nothing (except multiple inheritances) that interfaces can do but abstract classes cannot?
d
Nothing that I can think of at the moment
👍 1