37
votes
5answers
8k views

How to make a Java class that implements one interface with two generic types?

I have a generic interface public interface Consumer<E> { public void consume(E e); } I have a class that consumes two types of objects, so I would like to do something like: public ...
36
votes
5answers
9k views

Method name collision in interface implementation - Java

If I have two interfaces , both quite different in their purposes , but with same method signature , how do I make a class implement both without being forced to write a single method that serves for ...
35
votes
11answers
16k views

Why is Multiple Inheritance not allowed in Java or C#?

I know that multiple inheritance is not allowed in Java and C#. Many books just say, multiple inheritance is not allowed. But it can be implemented by using interfaces. Nothing is discussed about why ...
23
votes
18answers
11k views

How do Java Interfaces simulate multiple inheritance?

I am reading "The Java Tutorial" (for the 2nd time). I just got through the section on Interfaces (again), but still do not understand how Java Interfaces simulate multiple inheritance. Is there a ...
23
votes
4answers
489 views

How to reference a generic return type with multiple bounds

I have recently seen that one can declare a return type that is also bounded by an interface. Consider the following class and interface: public class Foo { public String getFoo() { ... } } ...
21
votes
4answers
3k views

Are defaults in JDK 8 a form of multiple inheritance in Java?

A new feature coming in JDK 8 allows you to add to an existing interface while preserving binary compatibility. The syntax is like public interface SomeInterface() { void existingInterface(); ...
16
votes
7answers
15k views

Java - Multiple inheritance

First of all... Sorry for this post. I know that there are many many posts on stackoverflow which are discussing multiple inheritance. But I already know that Java does not support multiple ...
13
votes
1answer
814 views

Java: How can I require a method argument to implement multiple interfaces?

It's legal to do this in Java: void spew(Appendable x) { x.append("Bleah!\n"); } How can I do this (syntax not legal): void spew(Appendable & Closeable x) { ...
11
votes
5answers
4k views

Why use Interfaces, Multiple Inheritance vs Interfaces, Benefits of Interfaces?

I still have some confusion about this thing. What I have found till now is (Similar questions have already been asked here but I was having some other points.) Interface is collection of ...
10
votes
6answers
416 views

How to implement interfaces with homographic methods in Java?

In English, a homograph pair is two words that have the same spelling but different meanings. In software engineering, a pair of homographic methods is two methods with the same name but different ...
9
votes
5answers
2k views

Virtual Extension Methods in upcoming Java 8 release

When I see code snippets like interface A { void a(); void b() default { System.out.println("b"); }; void c() final { System.out.println("c"); }; } I have one question. ...
9
votes
6answers
1k views

Java: how do you call this multiple inheritance ambiguity?

Here's an example using multiple interface inheritance in Java and there's an issue. Note that I fully know why there's an issue and this is not the point of my question. The question is about how ...
8
votes
7answers
1k views

Why make Abstract classes and Interfaces?

Well I was going to ask what the difference is but it's been answered before. But now I'm asking why did they make these differences? (I'm speaking about java here, I don't know if the same applies to ...
8
votes
6answers
679 views

Multiple inheritance design issue in Java

How do you deal with having only single inheritance in java? Here is my specific problem: I have three (simplified) classes: public abstract class AbstractWord{ String kind; // eg noun, ...
8
votes
1answer
84 views

“&” or “,”: What is the difference between A<T extends I1 & I2> and A<T extends I1 , I2>

Multiple generic interface separator: "," or "&" I was always using A<T extends I1, I2> but today, I saw A<T extends I1 & I2>. What is the difference between these two notation? ...

1 2 3 4 5 7
15 30 50 per page