Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice for inheritance #159

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ So we can maintain a cross language type mapping:
| **OTHER COMMON USING TYPE** | | |
| **big decimal** | java.math.BigDecimal | github.com/dubbogo/gost/math/big/Decimal |
| **big integer** | java.math.BigInteger | github.com/dubbogo/gost/math/big/Integer |
| **Boolean** | Boolean | \*bool (TODO) |
| **Integer** | Integer | \*int32 (TODO)|
| **Long** | Long | \*int64 (TODO)|
| **Double** | Double | \*float64 (TODO) |

## reference

Expand Down Expand Up @@ -225,3 +221,34 @@ The encoded bytes of the struct `MyUser` is as following:
00000030 4e 75 6d 62 65 72 60 08 75 73 65 72 6e 61 6d 65 |Number`.username|
00000040 0c 30 31 30 2d 31 32 33 34 35 36 37 38 |.010-12345678|
```

## Notice for inheritance

`go-hessian2` supports inheritance struct, but the following situations should be avoided.

+ **Avoid fields with the same name in multiple parent struct**

The following struct `C` have inherited field `Name`(default from the first parent),
but it's confused in logic.

```go
type A struct { Name string }
type B struct { Name string }
type C struct {
A
B
}
```

+ **Avoid inheritance for a pointer of struct**

The following definition is valid for golang syntax,
but the parent will be nil when create a new Dog, like `dog := Dog{}`,
which will not happen in java inheritance,
and is also not supported by `go-hessian2`.

```go
type Dog struct {
*Animal
}
```