170 questions
0
votes
2
answers
109
views
Interface overriding extending functional interface method as default and having an abstract method works abruptly
@FunctionalInterface
interface StringConsumer extends Consumer<String> {
@Override
public default void accept(String s) {
System.out.println(s.toUpperCase());
}
void ...
1
vote
1
answer
272
views
Java 17: MenuIterator is not abstract and does not override abstract method remove() in java.util.Iterator
I'm getting the following error while implementing the java.util.Iterator interface in my class:
java: MenuIterator is not abstract and does not override abstract method remove() in java.util.Iterator....
2
votes
0
answers
60
views
VerifyError on Kitkat when code explicitly calls a default method
When instantiating a class that has code to explicitly call a default method for an interface that it implements, a java.lang.VerifyError is thrown. This happens on Kitkat (API 19), but Lollipop and ...
0
votes
1
answer
356
views
can abstract method do System.out.println?
I am a beginner in Java. I have a question about the abstract method in Interface. Is the following sampleMethod() an abstract method? My understanding is that it is not an abstract method due to ...
5
votes
0
answers
46
views
Why is interface default method shadowed by parent private method? [duplicate]
I don't understand why an IllegalAccessError exception is thrown from the example below. The method foo() in Parent cannot be inherited by Child, because it is private. But trying to call the default ...
5
votes
2
answers
308
views
What is the point of the Functor -> Applicative -> Monad hierarchy [duplicate]
What is the point of making Functor a super class of Applicative and Monad. Both Applicative and Monad immediately imply the only implementation of Functor that abides by the laws as far as I can tell....
0
votes
1
answer
396
views
Is it possible to implement native methods in interfaces?
You often hear that methods in an interface have no implementation. However, in Java 8 it became possible to implement the default methods.
But I'm interested. Was and is it possible to implement ...
0
votes
0
answers
94
views
cannot call default method of parent interface using super [duplicate]
interface WithDefinitionsInter {
default void definedMeth() {
System.out.println("inside interface");
}
}
class WithDefinitionsImpl implements WithDefinitionsInter {
...
2
votes
1
answer
661
views
Where are the default methods of interface stored in memory?
I have gone through a number of posts, but all seem to answer that where are the static methods of an interface stored. However, an interface can have abstract, static and default methods. I know ...
4
votes
0
answers
125
views
Calling interface's default method when superclass has private method
Consider the code below.
interface I {
default Number f() {
return 0;
}
}
class A {
private Number f() { // if Number is replaced with other type, all will work fine
...
4
votes
2
answers
167
views
Would it be possible to add default methods to Comparable without breaking Java?
I was thinking of proposing a feature request to add default methods called:
default boolean greaterThan(T o) {
return compareTo(o) > 0;
}
default boolean smallerThan(T o) {
return ...
21
votes
3
answers
16k
views
Lombok @Slf4j and interfaces?
I am trying to add logging to my interface default method. For example:
@Slf4j // not allowed
interface MyIFace {
default ThickAndThin doThisAndThat() {
log.error("default ...
-1
votes
1
answer
143
views
Using default class members in VBA projects used as external reference
I tried to add one VBA project Lib as reference for a second VBA project App and the default class members don't work.
Is this a limitation of VBA? Or is there something I need to do to get it to work?...
3
votes
2
answers
512
views
C# Code reuse ( Default Interface Methods / Extensions )
I would like to ask for an advise. I am learning C# and I am always trying to reduce code duplication and I am struggling to find "best practice" in C#.
I am trying to use Default interface ...
9
votes
2
answers
820
views
Using default method raises AbstractMethorError in Android release build
I have an interface that inherits from Android's TextWatcher to only implement afterTextChanged method. I have enabled Java 8 support in my project, and added source and target compatibility options ...
2
votes
1
answer
294
views
Why this type is not an Interface?
I want to make an interface with default implementation for equality and comparison functions.
If I remove everything from the type IKeyable<'A> except the Key member, it is a valid interface, ...
1
vote
1
answer
352
views
Type-variable-dependent default method implementation in Haskell
I am trying to define default method implementations, but only if the class's type variables derive certain other classes.
I have tried creating type-dependent instances using => (am I even using ...
3
votes
1
answer
112
views
Java default methods with lambda
I am learning the Java 8 syntax and came across a piece of code in our application below in an interface:
default EmployeeEnricher employeeEnricher() {
return builder -> {
return;
...
0
votes
0
answers
641
views
@JvmDefault not found sourceCompatibility/targetCompatibility assigned by project variable [duplicate]
I want to provide default implementation for method in my Kotlin interface:
interface INavItem : Comparable<INavItem> {
val order: Int
@JvmDefault
override fun compareTo(other: ...
-3
votes
2
answers
425
views
why default method not recognized as property(getter/setter)?
Interface:
public interface SomeInt{
Integer getX();
void setX(Integer value);
default Integer getY(){
return getX();
}
default void setY(Integer value){
setX(value);
}
...
1
vote
2
answers
87
views
Call default method from other interface in another default method
This code crashes:
public class MyClass {
public static void main(String args[]) {
Person person = new Person();
person.selectMe();
}
}
class Entity {}
interface EntityNameable&...
4
votes
2
answers
236
views
Explicitly calling a default method in java - when the implemented interface uses generics
This questions is the same as this one with a twist.
I have an interface such as :
@Repository
public interface InvoiceRepository extends JpaRepository<Invoice, String>{
// some other ...
0
votes
4
answers
2k
views
default method in interfaces
For a while I have been puzzled as to why we need default methods in Interfaces, and today I was reading about it. Even though few of my questions are answered, I still have a few queries.
Let's take ...
6
votes
2
answers
4k
views
Kotlin enforce implementing class to be a supertype of another type
Since multiple inheritance is not allowed in java/kotlin, it's usefull to take advantage of interface default methods. Given example:
abstract class Animal {
fun beAnimal() {
println("I'...
2
votes
2
answers
459
views
Does interface provide full abstraction? How?
As much i know interface provides full abstraction because it can't have any concrete method like abstract class. But from java 8, interfaces can have concrete methods using default keyword and the ...