On 03.01.2012 09:42, david koch wrote: > Hello, > I try to use the Bundle.adapt method with Java 1.7.0_02 in the following > way: > > Framework framework; > FrameworkStartLevel startLevelObject = > framework.adapt(FrameworkStartLevel.class); > > This is ok for the Eclipse compiler (1.7) but when I try this with gradle > or with plain javac on command line I get the following compiler error: > error: incompatible types > FrameworkStartLevel startLevelObject = > framework.adapt(FrameworkStartLevel.class); > required: FrameworkStartLevel > found: Object > > This compiler error I get with 'org.apache.felix.framework-4.0.2' as well > as with 'org.osgi.core-4.3.0' fetched from Maven repository.
Welcome to the wonderful world of half-compatibility gone wrong. :/ You're not the first to stumble over this: https://mail.osgi.org/pipermail/osgi-dev/2011-August/003223.html > >javap org\osgi\framework\Bundle -classpath . -verbose > Compiled from "Bundle.java" > public interface org.osgi.framework.Bundle extends java.lang.Comparable > Signature: length = 0x2 > 00 50 > SourceFile: "Bundle.java" > minor version: 0 > major version: 48 > ... > > How can I use this with Java 7 or is this not possible? Why is the target > platform 48 (1.4) but the source is at least 1.5. Does this make any sense? Depending on your POV it makes a lot of sense if you know the history. The OSGi alliance decided that 4.3+ jars be built with the unknown, unsupported and - as of JDK7 apparently dead - option "-target jsr14", which enables a subset of JDK5 features (i.e. generics) while still allowing the generated bytecode to run on JDK 1.4. Since JDK7 the compiler does additional method signature verification (amongst other things to fix broken behaviour in JDK6). Consequently it gets very confused that 1.4 bytecode suddenly has generics, and pop goes your weasel. More info: http://stackoverflow.com/questions/4058661/java-compilers-target-version-jsr14-with-jdk7-8 AFAIK there is no good solution to this other than: - using the eclipse compiler instead (please try and report back!) - building with JDK6 (if you don't need JDK7 features) - rebuilding the OSGi framework with 1.7 javac :-( I currently resort to using JDK6 for building bundles which require generics in OSGi interfaces. Another great exanmple not inconveniencing anyone at all cost.. cheers -h --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@felix.apache.org For additional commands, e-mail: users-h...@felix.apache.org