Don't believe me? have a look at default functions for interfaces in Java 8. It's like the know they need MI, but they don't want to admit it, so they've found a convoluted way of doing the same thing.
The best part? If an interface is entirely default methods, an anonymous inner class can instantiate it with minimal code:
MyInterface inst = new MyInterface(){};
So they're like real classes. I don't know about you, but for me, this sure seems like they want MI but are too afraid to admit it.
EDIT: Oh, and if you want instance variables, all you need is a static Map that maps instances of the interface to the instance members.
interface A
{
void f() default
{
System.out.println("f");
}
}
interface B
{
void g() default
{
System.out.println("g");
}
}
class C implements A, B
{
}
//...
C c = new C();
c.f();
c.g();
Oh I see. Well that's weird, that removes the whole point behind interface. Because now you could create a diamond effect in Java. As both interface could have a default function with the same name but different outcome.
I can't see a problem here. Looks like they just borrowed traits from Scala. The diamond problem is easily solvable because if you inherit the same method twice, you *have* to provide a disambiguating implementation in the subclass. It is *not* MI, because you still can't have constructors in those interfaces. What makes C++ MI horrible is object construction and inheritance of state.
So you are changing your story that MI is bad and shouldn't be included in any language. Now that it is being included into Java it's just C++ that's terrible. Ok.
What happens if two inherited classes inheriting the same base class need to construct the base in a different way? There is also no linearization / fixed order of super classes in C++, contrary to Scala, Java and Python.
So you are changing your story that MI is bad and shouldn't be included in any language
Java has had MI of interfaces since version 1.0. What Java hasn't had is MI of classes. MI of classes is bad and Java 8 *does not* add it.
What happens if two inherited classes inheriting the same base class need to construct the base in a different way?
The same thing as with the diamond problem; the inheriting class has to provide a disambiguating call in its ctor.
rapidcoder wrote:
There is also no linearization / fixed order of super classes in C++
I was not aware that this was even possible. I'd like to know how Java Interfaces have an order, and how Python MI does it, because you could easily multiply inherit two differently-ordered hierarchies of the same base classes.
rapidcoder wrote:
MI of classes is bad and Java 8 *does not* add it.
With the ability of interfaces to contain definitions for methods now, the only thing missing is language-enforced ctor calls. Java 8 Interfaces are basically classes that you can multiply inherit, since they now allow all the convenience of MI. Mind you, using a static map to access member vars is not desirable, but it's certainly quite an advantage.
Ofc I'm not saying it's officially MI, just pretty darn similar.
@LB, you're being silly. You may as well claim that all languages have multiple inheritance, because you can hack a map for functions, similarly as you suggest for variables.
@LB, okay, first, they did not want MI, they wanted lambdas (or, rather, a way to extend interfaces to use them). Second, do you actually think this is bad? The kind of MI that doesn't have variables is pretty much impotent to do harm. Third, did you really have to phrase it like that? When accusing a language of hypocrisy for adding a shade of a feature it didn't previously have, don't expect to be taken seriously.
1. I know what the intended use is. My point is that it looks very much like MI.
2. I think it's great, if not funny. I'm a supporter of MI.
3. I phrased it the way I saw it. It seriously looks like they're trying to find a way around calling it MI. At least to me it looks that way, anyway.
I didn't expect you to take offense; I really didn't mean to offend anyone (though I will admit I was on the offensive toward rapidocder).
seems like the java community will also realize one day just how powerful the concepts of c++ templates are and will try implementing some java style templates (not generics stuff as this does not have the same abilities of templates, ie templates allow metaprogramming that is not possible with java generics).
MI helps cut down code for required functionality in many cases. Add real templates on top of that and the effects should be even more devastating to a java developer who would typically have to create more code to cater for same required functionality.
@SIK:
different languages for different uses. I don't know why people come down with terms like Java or C++ or (insert language) communities. Good programmers learn and use many languages based on what they are doing.
I like C++ for game programming. However I prefer to make business apps or Web apps with C#. I don't think either one language is "better" then the other. True I personally don't really like Java, however that is of personal preference because I learned C# first (and they are very similar languages). But I also use HamsterSpeak (http://hamsterrepublic.com/ohrrpgce/docs/plotdict.xml) because it was the scripting language designed for an engine I used.
I understand that, however, ones favorite language does not make it better. and does not need to have the same functionality as it they often times used for different things.
Edit:
But it is easy to get caught up in language wars, I do so with C# vs Java all the time :p
hey guys dont mean to intrude but i figured while you were talking about language wars, what does c# give you that c++ doesnt. i think i read somewhere that you can switch strings which is nice, but i wouldnt use it over c++ based on that one feature. also, what does .net give you?