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

generix collections in Ruby land #3795

Open
kares opened this issue Apr 12, 2016 · 5 comments
Open

generix collections in Ruby land #3795

kares opened this issue Apr 12, 2016 · 5 comments

Comments

@kares
Copy link
Member

kares commented Apr 12, 2016

suppose a collection (or any other generic type) such as java.util.ArrayList never leaves Ruby-land.

such as presented here: #2049 (comment) (implicit conversion leading to user confusion on times)

in cases such as those it might not be desirable for type conversions to be happening whenever a java.lang.Object boundary is seen (e.g. list.add Time.now). but instead of tricky escape-analysis a reasonable way this could work is if target type information was available. some quick ideas :

list = java.util.ArrayList.of(org.jruby.RubyTime)
list.add Time.now # no conversion

list = java.util.LinkedList.new
list.typed! 'RubyString'

set = java.util.HashSet['java.lang.Integer'].new 
# true types Set<Integer> - could work for any generixized type

# the last example might become very real with Java 9 around
# ... since we would likely want to be able to : 
set = java.util.HashSet[:int].new # Set<int>

consequences of such wrapped Java types is that their need to become __persistent__ to store additional generic type information. except maybe on Java 9 where there likely is to be a way to tell a Set<Integer> from a Set<int>

@enebo
Copy link
Member

enebo commented Apr 12, 2016

@kares fwiw I don't think we will ever escape that coercion away. I am also not even sure even if we could see something escape we would anyways. Once you convert it is really a different object at that point.

I like the spirit of this enhancement. People who need the power will be willing to type their collections in such a way to prevent coercion. Most people will not care and will not do this but that is fine. This just gives us another level of control in how we interact with Java from Ruby.

@kares
Copy link
Member Author

kares commented Apr 12, 2016

yeah, the escape was mostly a note for people expecting that if its all in Ruby it should behave differently.

like the typed collection java.util.HashSet[:int] syntax although it would only allow for typing of those created from within Ruby. not sure I like set.typed! :int or any similar method. do you think we would need to support externaly created "typed" collections? hoping its really not that important.

also wonder whether that syntax should disable any conversion e.g. java.util.ArrayList[nil].new ?

@enebo
Copy link
Member

enebo commented Apr 12, 2016

Makes me wonder if we can just make a class method to return an uncoercing instance. At least for non-primitive types: java.util.ArrayList.new!.

Is there value to enforcing the type? I think primitives takes down a whole different rabbit hole...

@kares
Copy link
Member Author

kares commented Apr 13, 2016

Makes me wonder if we can just make a class method to return an uncoercing instance. At least for non-primitive types: java.util.ArrayList.new!.

sounds like a simple good start and if it is to be implemented it would likely work on all Java proxies, yay :)
although it probably gets internally a little ugly to check on all those places whether toJava should happen.

@headius
Copy link
Member

headius commented Nov 21, 2017

Note: Java 9 does not include any generic reification, nor will the next couple years of updates (most likely).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants