Skip to content

Instantly share code, notes, and snippets.

@arnaudbreton
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudbreton/85f93d187d2b183e40bc to your computer and use it in GitHub Desktop.
Save arnaudbreton/85f93d187d2b183e40bc to your computer and use it in GitHub Desktop.
dotGo 2014
class ExplicitStringer implements Stringer {
public String String() {
return "I am a real Stringer!";
}
}
Main.java:11: error: method print in class Main cannot be applied to given types;
Main.print(notStringer);
^
required: Stringer
found: NotExplicitStringer
reason: actual argument NotExplicitStringer cannot be converted to Stringer by method invocation conversion
1 error
package main
import (
"fmt"
)
type ImplicitStringer struct {
value string
}
func (s ImplicitStringer) String() string {
return s.value
}
func Print(stringer fmt.Stringer) {
fmt.Println(stringer)
}
func main() {
s := ImplicitStringer{
value: "42",
}
Print(s)
}
public class Main {
public static void main(String [] args) {
// Works because ExplicitStringer
// explictly implements Stringer interface
ExplicitStringer stringer = new ExplicitStringer();
Main.print(stringer);
// Does not compile because NotExplicitStringer does not
// explictly implements Stringer interface
NotExplicitStringer notStringer = new NotExplicitStringer();
Main.print(notStringer);
}
public static void print(Stringer stringer) {
System.out.println(stringer.String());
}
}
class NotExplicitStringer {
public String String() {
return "I am concrete!";
}
}
type Stringer interface {
String() string
}
public interface Stringer{
string String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment