To implement an interface in Java the interface type must be listed in the class declaration. Emulate the implicit Go interface implementations in Java by listing all possible (non-empty) interfaces. For example, given type ( S struct{} I interface { M() } ) func (s *S) M() { } in Go, the Java class S will be declared to implement the Java interface I. Fixes a TODO. Change-Id: I5b0d2dd65938004ab29029f481cace4b8fb4b26f Reviewed-on: https://go-review.googlesource.com/19417 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
37 lines
506 B
Go
37 lines
506 B
Go
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package structs
|
|
|
|
type S struct {
|
|
X, Y float64
|
|
unexported bool
|
|
}
|
|
|
|
func (s *S) Sum() float64 {
|
|
return s.X + s.Y
|
|
}
|
|
|
|
func (s *S) Identity() (*S, error) {
|
|
return s, nil
|
|
}
|
|
|
|
func Identity(s *S) *S {
|
|
return s
|
|
}
|
|
|
|
func IdentityWithError(s *S) (*S, error) {
|
|
return s, nil
|
|
}
|
|
|
|
type (
|
|
S2 struct{}
|
|
I interface {
|
|
M()
|
|
}
|
|
)
|
|
|
|
func (s *S2) M() {
|
|
}
|