-
Notifications
You must be signed in to change notification settings - Fork 82
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
ij.py.from_java() returns scyjava.JavaList when input is java.util.ArrayList #100
Comments
@carshadi Thanks for the report. It's confusing because when converting collections from Python to Java, data is copied. But when converting collections from Java to Python, the Java objects are wrapped using Python duck typing. So the type That said, I believe there are a couple of gaps in the implemented functions of the Python collection wrappers. Not sure about Now that we're using JPype, it's often the case that you don't need the >>> import scyjava
>>> def process_list(l):
... for i in l:
... print(i + i)
...
>>> process_list([1, 2, 3, 4])
2
4
6
8
>>> ArrayList = scyjava.jimport('java.util.ArrayList')
>>> jl = ArrayList([1, 2, 3, 4])
>>> process_list(jl)
2
4
6
8
>>> jl = ArrayList(['a', 'b', 'c', 'd'])
>>> process_list(jl)
aa
bb
cc
dd
>>> process_list(['a', 'b', 'c', 'd'])
aa
bb
cc
dd
>>> jl + jl
<java object 'java.util.ArrayList'>
>>> print(jl + jl)
[a, b, c, d, a, b, c, d]
>>> set(jl) - set(['b', 'd'])
{'a', 'c'} If you really need a true >>> list(jl)
['a', 'b', 'c', 'd'] So hopefully that's good enough for now! Still, let us know if there are specific conversions you need that aren't working. |
thanks, this is helpful. casting with |
I'm not sure if this is the intended behavior, but the Usage.md states the return type should be a Python
list
Running
pyimagej 1.0.0
installed via conda-forge withopenjdk 8.0.265
in a jupyter notebookThe text was updated successfully, but these errors were encountered: