-
Notifications
You must be signed in to change notification settings - Fork 21
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
Object expressions should allow for new interface implementations, and fit into parameters of said interface #944
Comments
I think this may be related to the fact that it isn't possible to implement an abstract class using object expressions without overriding at least one member (see related SO question). You can work around this limitation by overriding one of let videoView = new Android.Views.VideoView(context)
videoView.SetOnPreparedListener({
new Java.Lang.Object() with
member _.ToString() = base.ToString()
interface Android.Media.MediaPlayer.IOnPreparedListener with
member _.OnPrepared player = () }) |
@FunctionalFirst |
@Happypig375 You're right—my mistake. There were no squiggles, but I see the same error if I send to interactive. |
I.e. type private ListeningJavaObject() =
inherit Java.Lang.Object()
interface Android.Media.MediaPlayer.IOnPreparedListener with
member _.OnPrepared player = ()
let videoView = new Android.Widget.VideoView(context)
videoView.SetOnPreparedListener(ListeningJavaObject()) If the intention of allowing the proposed code over the explicit class is to save one line, that not a real advantage. If the intention is to allow a more local definition, then #150 would be better way to do it, although a much larger feature to implement. But since there are several new issues about anonymous classes and interfaces it might be considered instead of implementing all of those. |
@Happypig375 The underlying object still implements the interface, so you could The missing feature here is object expressions having an anonymous type when they inherit/implement more than one type. As for the unnecessary override for the parent type, #632 is approved, but missing an RFC. |
This is by-design, as it's useful and important to check that the interfaces are related to the type being implemented. We won't be adjusting that decision
Yes, this is the rest of the matter here, covered by #632 |
I propose we allow
The existing way of approaching this problem in F# is writing a boilerplate class.
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantage of making this adjustment to F# is that object expressions may be too niche to be improved. However, it is a niche exactly because of cases like these where it cannot be used.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: