Questions tagged [default-method]
A default method is a feature introduced in Java 8 which allows an interface to declare a method body. Classes which implement the interface are not required to override a default method. Use this tag for questions relating to default methods.
default-method
169
questions
0
votes
1
answer
31
views
default method executed instead of implementation
When calling findBySubstring() from ArticleAutocompleteServiceImpl - default method of interface is executed instead of implementation. Is it because of generics? What did I do wrong? How to keep this ...
1
vote
1
answer
160
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....
1
vote
1
answer
99
views
Override Object methods inside interface using default methods- Misleading error
Question: Need to understand why in case of Program 1 getting this misleading error, but in Program 2 it gives correct error? Also why unlike toString(), equals(Object), and hashCode(), overriding ...
1
vote
0
answers
47
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
2
answers
914
views
How can I write a junit test case for default methods of interface with zero lines of code
How can I write a junit test case for default methods of interface with zero lines of code as mentioned below :
public interface A{
default void method1(){
}
}
0
votes
1
answer
282
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 ...
0
votes
1
answer
54
views
Selecting default implementation from indirectly inherited Interface not working
I have 4 Classes that look like this:
public interface Foo<T> {
...
default boolean isEmpty() {
return false; //dummy value real implementation is not relevant for the problem
}
}
public ...
5
votes
0
answers
45
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 ...
1
vote
1
answer
97
views
Class inheriting same method from two different interfaces and a single default implementation won't compile
I have stumbled upon a strange issue working with default methods.
Consider this situation:
interface A {
int method();
}
interface B {
default int method() {
return 1;
}
}
class ...
5
votes
2
answers
276
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....
1
vote
1
answer
3k
views
OpenAPI generator returns 501 for implemented method
I've generated rest api with openAPI generator maven plugin and I've overridden the default method from MyApiDelegate interface, but POST request on /endpoint provides 501 NOT IMPLEMENTED as if I hadn'...
0
votes
1
answer
333
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 ...
1
vote
1
answer
230
views
Override DefaultGroovyMethods method
Is there a way to easily override toSet(Collection<T> self) method from DefaultGroovyMethods?
Its implementation uses HashMap
public static <T> Set<T> toSet(Collection<T> self) ...
0
votes
0
answers
88
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
129
views
Why, after compiling an interface, "default" method modifier is gone from "javap -v"?
I have observed, that after compiling an interface containing default method definition, like:
interface Delta {
default void someMethod() {
System.out.println("Hi.");
}
}
...