Recently I've been asked a question which is, what's the difference between Golang and Java about interface?
I know there are some 'syntax-sugar level' differences, what I am interested is anything beneath the ground, like how does Golang and Java implement interface? What's the biggest difference? Which one is more efficient? Why?
Could anyone post blog links or source code about this topic? The only code I can find is in src/runtime/iface.go, but I cannot understand it or get anything useful by myself yet. Source code is better.
Thanks.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Go does not have functional interfaces or interface literals.
-j
But that is just syntactic sugar around the fact that Java does not have first class functions. At least not in the sense Go does.
In Java, if an interface contains exactly one method, and that method is not already part of java.lang.Object, the syntaxInterface i = (arguments) -> {code};will make an object i of that interface type with the given closure as the method body. This interface is called a functional interface.Pre-Java 8, the same thing could be done withInterface i = new Interface() {public void method() {code}};
Yet a notable such marker interface Serializable is known by almost all Java developers ;)
--