Git Product home page Git Product logo

Comments (8)

flying-sheep avatar flying-sheep commented on August 23, 2024

also System.out.print is a syntax error without from __future__ import print_function, but that isn’t important ;)

if we’d really need it, we could use autoclass('java.lang.System').out.__getattribute__("print")("woo")

from pyjnius.

tshirtman avatar tshirtman commented on August 23, 2024

Confirmed, thanks for reporting, looking into how to add this to our method signature lookup :)

from pyjnius.

flying-sheep avatar flying-sheep commented on August 23, 2024

nice. please remember to create tags as soon as bigger features like that (or the upcoming import hook) come in, they help with knowing when to package a new version.

from pyjnius.

jishi9 avatar jishi9 commented on August 23, 2024

As an aid for adding this feature (and also as a work around) you can do the following:

# Empty vararg
System = autoclass('java.lang.System')
System.out.printf('string' ,[])

# Note: Using python strings does NOT work
String = autoclass('java.lang.String')
System.out.printf('my string is %s', [ String('this') ])

The reason for this is that Java internally converts the varargs into a single array parameter.

Also note that in addition to getting printed to stdout/stderr, calling printf also seems to return a PrintStream object. I am assuming that some special-case code ensures that this does not happen with print and println?

from pyjnius.

tshirtman avatar tshirtman commented on August 23, 2024

Thanks for the list tip, i was there too :)

Our parser currently doesn't know if a list in signature is a varargs list or not, seems we are not the first ones to run into this issue, if we can detect that, it should be easy enought to adjust our calculate_score method.

For the unability to build a list of python strings directly, i was about to open a bug report, at least to discuss those workarounds and if we can find a better solution (same issue with building lists of numbers and probably other things).

edit: found about isVarArgs, that allow at least to know if a method is varargs… :)

from pyjnius.

flying-sheep avatar flying-sheep commented on August 23, 2024

We should convert between python and Java strings always and implicitly. Trying to use autoclass on java.lang.String should yield a warning that you'll be dealing with python strings no matter what you do.

Reason is that python strings can do anything Java strings can do, and this change would make anything easier.

Btw.: so you already translate toString to __str__?

from pyjnius.

tshirtman avatar tshirtman commented on August 23, 2024

Ok! sorry it took so long, but we now have at least some basic support of varargs in the varargs_support branch, test case for printf as been added, more test cases with more exotic objects welcome :)

from pyjnius.

tshirtman avatar tshirtman commented on August 23, 2024

I'll close this since support has been added, feel free to reopen if support is incomplete.

from pyjnius.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.