简体   繁体   中英

Pass Scala Seq into Scala function from Java

I have been smacking my head against the table for hours. I am trying to call a function that is written in a library that takes Seq<Object> as the only argument type. The problem is, I can't seem to be able to construct anything that Scala wants to recognize as a collection type.

I've tried everything from using Scala Buffers and the like and trying to convert to a Seq or using the $colon$colon stuff. Nothing works can someone please point me in the right direction.

EDIT:

This is the code I'm using at the moment

    List<Object> objs = new ArrayList<>();

    Object obj = new Object();
    objs.add(obj);   

    function(JavaConversions.asScalaBuffer(objs));

Which has no errors but I receive java.lang.String cannot be cast to [B

I omitted some arguments to new Object() since it is sensitive data

thanks

java.lang.String cannot be cast to [B means you're trying to pass a String to a method that calls for a byte[] (that's what [B means).

Try calling getBytes on your String and that should fix your problem.

(Note: It appears your problem has nothing to do with the code you posted. Maybe it's in the "sensitive" part that you removed.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM