jvm-languages

How do I invoke a Java method from perl6

放肆的年华 提交于 2019-12-03 07:41:59
use java::util::zip::CRC32:from<java>; my $crc = CRC32.new(); for 'Hello, Java'.encode('utf-8') { $crc.'method/update/(B)V'($_); } say $crc.getValue(); sadly, this does not work Method 'method/update/(B)V' not found for invocant of class 'java.util.zip.CRC32' This code is available at the following links. It is the only example I've been able to find Rakudo Perl 6 on the JVM (slides) Perl 6 Advent Calendar: Day 03 – Rakudo Perl 6 on the JVM Final answer Combining the code cleanups explained in the Your answer cleaned up section below with Pepe Schwarz's improvements mentioned in the

Adding default package imports

假如想象 提交于 2019-12-03 07:05:57
In Java, Scala, or generally any JVM language, there is a set of packages that is imported by default. Java, for instance, automatically imports java.lang , you don't need to do it in your Java code file. Now I don't know which component takes care of this exactly (the compiler? the JVM?), but is there any way to have additional packages or even classes imported by default? Say you have a package defining a set of utility functions you use throughout your project (an example could be scala.math in Scala), it would be great if you were able to skip the import for it in every math related class.

Groovy advantages over Jython or Jruby?

感情迁移 提交于 2019-12-03 01:41:15
问题 Why would I choose to use Groovy when I could use Jython or Jruby? Does the language provide any inherent advantages to make up for the fact that Jython and Jruby skills are applicable to their parent languages outside of the JVM? Keep in mind that I purposely keeping this question generic, but if there are any advantages that exist in a particular domain, please don't hesitate to describe them. EDIT To clarify, If I write some code in Jruby, I can now, in some cases, move that code outside

In Scala, how do I get the *name* of an `object` (not an instance of a class)?

本秂侑毒 提交于 2019-12-02 19:09:33
In Scala, I can declare an object like so: class Thing object Thingy extends Thing How would I get "Thingy" (the name of the object) in Scala? I've heard that Lift (the web framework for Scala) is capable of this. Just get the class object and then its name. scala> Thingy.getClass.getName res1: java.lang.String = Thingy$ All that's left is to remove the $ . EDIT: To remove names of enclosing objects and the tailing $ it is sufficient to do res1.split("\\$").last If you declare it as a case object rather than just an object then it'll automatically extend the Product trait and you can call the

What happend to groovy++? [closed]

五迷三道 提交于 2019-12-01 19:53:49
I just stumbled upon groovy++ and found it quite interesting. Unfortunately it seems that it's not further developed? According to github the last commit was over a year ago. The mailing list is totally inactive and the last message was back in april. There are no recent news about it. Has the project moved and has another name now? Has it become obsolete because of improvements to groovy? Or is it just discontinued? Thanks for any insight! tim_yates Groovypp stopped being updated about a year ago, and should be considered discontinued afaik. Static compilation is now being added to Groovy 2.0

Sending a POSIX signal from the JVM

為{幸葍}努か 提交于 2019-12-01 13:53:59
问题 How do I send a POSIX signal from within the JVM? (in Java or Clojure) I never thought this would be an issue until I tried googling it — there is lots of information about handling signals, but nothing about sending them. Short of using the JNI or calling the shell to execute "kill", is there any other way to send a signal to a PID? 回答1: Ok. Answering myself: I looked at the suggested libraries, but I am wary of introducing new dependencies on lots of code, especially if I'll only use a

Comparison of XML parsing APIs on the Java SE platform

☆樱花仙子☆ 提交于 2019-11-30 19:38:40
问题 I am currently developing an RSS feed reader, and I am wondering which XML parsing API would be the best fit for that. (Please note that I am not looking for a Feed parser library - it is merely the starting point for that research about XML APIs) I am looking for a rundown of the various XML parsing APIs on the Java platform, focusing on the following criteria: Ease of configuration Is the configuration in a separate file? Are there reasonable defaults? Ease of use Node navigation - to

Stack-based machine depends on a register-based machine?

こ雲淡風輕ζ 提交于 2019-11-30 16:06:33
Normal CPUs (for example, Android devices) are register-based machines. The Java virtual Machine is a stack based machine. But does a stack-based machine depend on a register-based machine to work? Can't stack-based machines run lonely, because it is not a OS? Are there any stack-based machine examples except the JVM? Some are saying 1 operand, 2 operand; why do you need this? The JVM does not mention the existence of registers anywhere. From its perspective, memory exists in only a few places, such as the per-thread stack, the method area, runtime constant pools, etc. That said, if you wanted

Generating a 'Hello, World!' class with the Java ASM library

余生颓废 提交于 2019-11-30 09:15:10
I have started messing around with the ASM API for a compiler project I am working on. However, I am finding that the documentation is less than clear for a newcomer in many places and I thought having a good solid example of generating a class that simply prints "Hello, World!" would be a great example to have on here. Currently, I can generate a class with a main() (using the ClassWriter, ClassVisitor and MethodVisitor classes) but I can't seem to work out how to generate main's body. Could anyone give me an example of generating a class file in ASM that: contains a main() creates a local

Canonical reference on JVM internals for programmer/developers [closed]

天大地大妈咪最大 提交于 2019-11-30 08:56:37
The title captures my question fairly well. I'm wondering if there is a good resource or leaping-off point for questions about how a JVM (not just HotSpot, but that's obviously the place to start) implements or handles a specific functionality? I'm not looking for the stuff that's in the JLS or JVM Spec -- I know to go there first. For example : When trying to understand performance issues, we often get into conversations not about what the spec says, but what contemporary best-practices look like in practical implementations. For example, there is some urban mythology that says "final classes