-
Notifications
You must be signed in to change notification settings - Fork 48
Adds support for optional mapping #189
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments, looks like a good step
|
||
public func emptyOptional() -> Int64? { | ||
Optional(javaOptional: empty()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand where the ofOptional and emptyOptional came from? I know this is generated but couldn't quite wrap my head around what the intent of these is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fun one:
Any method that returns a Java optional (or friends) now has a second method that returns a swift optional and does wrapping. A fun consequence of this is that all optionals have static methods to create themselves ... which then have a helper generated to make a swift optional. It's a fun bit of recursion-ish stuff
@JavaMethod | ||
open func orElseThrow() -> JavaObject! | ||
} | ||
extension JavaClass { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to be how we import static methods/functions for classes that have generic parameters. Seems to be the same way we do it for HashMap
since the logic for the generic gets put into the function itself. Unless I misunderstood what you meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I see (note: I've not spend much time with JavaKit but more focused on the opposite direction, so thanks for helping review this 😄)...
Yeah that makes sense I guess, I wonder if this will become a problem in the long term with names clashing -- lots of types like to have a of(_:)
or some form of create(_:)
but maybe it'll work out okey, could be a lot of overloads eventually hm
Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift
Outdated
Show resolved
Hide resolved
A bunch of compile errors discovered by the Sample, please check |
Updated the code to get it running correctly with more samples! |
Very nice, thanks again :-) |
Closes #92
Adds support for methods and variables with optional. I went for an approach of making a wrapper func/var with the
Optional
suffix, but am open to other ideas. Also fixed up the Makefile so i could use it