``` interface Some { fun calculate(str: String? ...
# announcements
r
Copy code
interface Some {
  fun calculate(str: String? = null)
}
class SomeImpl : Some {
  fun calculate(str: String? = null)
}
An overriding function is not allowed to specify default values for its parameters Why?
l
That does not stop you from calling it without parameters, no?
The overloading is “handled” by the interface
r
but why I can not specify same default parameter in implementation?
l
I guess it’s to not break the interface’s contract
s
@rrader That would violate one of the SOLID principles, in this case the L(iskov substitution principal).
r
How it can break if it is the same default value?
s
If it is the same, you don’t have to specify it in its implementation.
r
I open the implementation class and I want to see that it can have a default parameter, if I will not open the interface than I will not know this
s
But the code that calls the
calculate(...)
functions, calls it on a variable that is declared to be of type
Some
, correct, not of type
SomeImpl
?
Copy code
val mySome : Some
...  
...
mySome = ... SomeImpl() ...
...
mySome.calculate()
r
it could be also a type of
SomeImpl
, why not?
s
Yup, but usually it won't be for the users of your
Some
instances (they should not be concerned with the specific implementation of an interface).