Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Example using the <a href="http://asm.ow2.org/" rel="nofollow noreferrer">ASM bytecode library</a> converted to work with .NET using the <a href="http://www.ikvm.net/userguide/ikvmc.html" rel="nofollow noreferrer">IKVM Java-to-.NET compiler</a>:</p> <p>hello.cs:</p> <pre><code>using System; using System.IO; using org.objectweb.asm; namespace test.helloWorld { public class helloDump { public static byte[] dump () { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(Opcodes.__Fields.V1_6, Opcodes.__Fields.ACC_PUBLIC + Opcodes.__Fields.ACC_SUPER, "hello", null, "java/lang/Object", null); mv = cw.visitMethod(Opcodes.__Fields.ACC_PUBLIC, "&lt;init&gt;", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.__Fields.ALOAD, 0); mv.visitMethodInsn(Opcodes.__Fields.INVOKESPECIAL, "java/lang/Object", "&lt;init&gt;", "()V"); mv.visitInsn(Opcodes.__Fields.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); mv = cw.visitMethod(Opcodes.__Fields.ACC_PUBLIC + Opcodes.__Fields.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); mv.visitFieldInsn(Opcodes.__Fields.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("Hello World!"); mv.visitMethodInsn(Opcodes.__Fields.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.__Fields.RETURN); mv.visitMaxs(2, 1); mv.visitEnd(); cw.visitEnd(); return cw.toByteArray(); } public static void Main(string[] args) { FileStream helloWorldFile = new FileStream("hello.class", FileMode.Create); byte[] helloWorldClass = dump(); helloWorldFile.Seek(0, SeekOrigin.Begin); helloWorldFile.Write(helloWorldClass, 0, helloWorldClass.Length); } } } </code></pre> <p>commands:</p> <pre><code>$ ikvmc -out:org.objectweb.asm.dll -target:library -version:3.2.0.0 asm-3.2.jar $ mcs -r:org.objectweb.asm.dll hello.cs $ mono hello.exe $ ls hello.class $ java hello </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload