How to create a struct with generic struct inside and init it in go , I see similar question here Generic Structs with Go but the fields is primitive type , I need the field of struct is generic and set this field as other struct
I try but it not work
type ResponseData[T struct{}] struct {
status int
error string
soaErrorCode string
soaErrorDesc string
clientMessageId string
path string
data T
}
And I try to init it
message := struct {
accountId string
}{
accountId: "0344561299",
}
bodyin := RoutinQueryInput[struct{}]{
Destination: "AAA-BBB",
Version: "1.2",
Message: message,
}
It said :
Cannot use 'message' (type struct {...}) as the type struct{}
In Java, we can create object generic inside a object , how to do that in go?
struct{}is not a typestruct{}is a type; it's just not a very useful one. It carries no data.