Java array in Silver

My Silver/Cooper project generates a JAR file. It uses Swift [] arrays (i.e. [Byte]) but I’d prefer if the Java output used native Java arrays (i.e. Byte[] instead of ArrayList<Byte>). What would be the most efficient way to obtain this?

You can use both:

[Foo] is a Swift array — a class. Foo[] is a platform-native array (a range of bytes in memory). See for more details.

Yet if I switch my method declaration (in the Silver/Cooper JAR) to:

func writeData(_ value: java.lang.Byte[])

Java sees it as:

void writeData(byte[] value)

How do I get it to generate:

void writeData(Byte[] value)

It’s as if the type didn’t map properly from Silver to Java. My main reason for wanting this is the fact that the app using my JAR file doesn’t need to know about Elements. I want the exposed classes to only use Java native types.

Hmm, that’s a separate issue though. TBH I’m not too familiar with Byte vs byte on Java, and how the compiler handles it exactly. maybe the array types always need to use Byte? I’ll have to defer to @ck to answer this one…

The important part WRT your original question is that you get Byte[], not [Byte]

You’ll want Byte![] in Swift to get a java.lang.Byte[] in Java.

1 Like

On a somewhat related note, if:

Consumer<java.lang.Byte[]> in my Silver/Cooper JAR becomes Consumer<byte[]> in Java

then why does:

Consumer<java.lang.Byte> in my Silver/Cooper JAR become Consumer<Byte> in Java?