-
Notifications
You must be signed in to change notification settings - Fork 205
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
Should struct types have a shared non-Object
supertype.
#2396
Comments
I can't see the harm in introducing a
Deciding if A counter-example would be some
#1290 presents similar arguments to those above: Sometimes, you want to represent a
Given the points above, I believe this would be optimal:
This should solve most if not all the problems at the cost of some complexity (although most users can just use
Maybe I'm missing something, but it sounds like "not a real object" would mean it's more useful to ask, "is this an
I think they should stay as regular objects since not needing to care about primitives vs objects is nice, unlike how Java always makes us think about |
(See #1290 for the similar questions for records.)
Should there be a
Struct
type which allstruct
declarations implicitly implement, and which no non-struct
type can implement?It allows recognizing that something is a struct.
That's potentially useful for not using it with an
Expando
, although I think we should put astatic bool isCompatible(Object? value)
method onExpando
so people don't have to check for 6+ different types. But we can useis Struct
insideisCompatible
then.(Should
num
,String
,null
andbool
implementStruct
then? Likely hard, since people useidentical
with them all the time today. Should records be structs, since they also has struct-like identity behavior?)Having
Struct
allows restricting types to only struct types withclass C<T extends Struct>
. Not sure when that would be necessary, though, since there is no code which works for structs and doesn't for classes.If anything, we'd want to restrict a type to non-structs, so you can use
Expando
on them.Looking at C♯, where
Value
is a supertype ofObject
and structs are non-Object
Value
s, that seems to be the more useful distinction. We just happen to have a lot of existing code which assumes thatObject?
is everything andObject
is everything exceptnull
.(If we designed from scratch, I'd put
Struct
/Value
aboveObject
, whereObject?
is today, and makenull
aStruct
.)So:
Struct
type? If so:Object
? (Probably, because otherwise our existing generics withObject
/Object?
as bound break down)Record
be a subtype ofStruct
? (Possibly, or they should share a common "not a real object" supertype.)num
,String
,bool
and/orNull
be subtypes ofStruct
? (Probably not, people depend on identity too much.)The text was updated successfully, but these errors were encountered: