0

I have some code that depends on jars that were compiled using Java 1.7. I am currently working on OSX, where I only have access to Java 1.6. I am currently attempting to recompile these jars locally. However, the jars only contained the .class files. I downloaded a disassembler and saved the resultant .java files. Now, there are some errors that I am currently trying to debug. One of the files checks to see if some parameter is equal to a class or type. The problem I'm having is that there is the expression

if (paramType.equals([D.class)) { ... }

which is causing a compiler error. What is the proper way of expressing a double array class?

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
etosch
  • 180
  • 7

2 Answers2

4

Assuming it's an array of (primitive) double:

if (paramType.equals(double[].class)) { ... }

Or if it's an array of (wrapper type) java.lang.Double:

if (paramType.equals(Double[].class)) { ... }
Holger
  • 285,553
  • 42
  • 434
  • 765
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Thanks for the quick response! Do you happen to know if the bytecode representation for the the array of primitives is `[D`? Or is `[D` the representation for the array of Objects? I have a bunch of other bugs I need to fix, so it'll be a while before I can test this out and actually get an answer... – etosch Nov 17 '12 at 18:59
  • I'm not sure about the bytecode representation (I rarely bother to look at Java bytecode) but I'm guessing that it comes from the [`Class#toString()`](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#toString%28%29) output for array types. See [`Class#getName()`](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getName%28%29) for more. – Matt Ball Nov 17 '12 at 19:03
  • 1
    “`equls`” should be “`equals`” but for classes, using `==` would be sufficient, i.e. `if(paramType == double[].class) { … }` – Holger Mar 29 '22 at 16:38
  • @Holger thanks for the correction. Why not suggest an edit though? :) – Matt Ball Mar 29 '22 at 18:55
  • 1
    It’s not an easy decision. I’d have changed it to `==`, but apparently, you prefer using `equals`… So I rather let the original author decide, as long as the author is still active. – Holger Mar 30 '22 at 07:00
0

If the classes don't link against any new library classes introduced in Java 1.7, then they should work just fine in Java 1.6, as the only bytecode features introduced in 1.7 are not actually used in Java.

All you have to do is change the 8th byte of every file from 51 to 50. You don't even have to disassemble and reassemble them.

Antimony
  • 37,781
  • 10
  • 100
  • 107