This is from a complex build system. And I am looking for help to localize the problem.
It seems like I am hitting this problem: Covariant Return Type in Interface not compiling via Javac
My code compiles fine when I compile after cleaning all compiled code. But if I open AImpl.java and change one character (modify any string literal, which shouldn't generate any compile time error) and compile then I get following error:
AImpl.java:22: types BImpl<T> and BImpl<T> are incompatible; both define waitFor(org.openqa.selenium.support.ui.ExpectedCondition,java.lang.String,long,java.util.Collection), but with unrelated return types
public class AImpl<T extends AImpl<T>> extends BImpl<T> implements A<T> {
This is specific to AImpl.java ; changing any other code doesn't generate this vicious error.
BImpl.java is defined as:
public class BImpl<T extends BImpl<T>> extends CImpl<T> implements B<T> {
The erroring method waitFor is defined in CImpl as:
public T waitFor(ExpectedCondition<?> condition, String message, long timeOutInMillis, Collection<Class<? extends Throwable>> exceptions)
Related
I seems to be running into a compilation error with a generic interface. The goal is to create an interface for use in my test classes the defines the common methods of a domain class and a generated DTO class. I did some digging and none of the answers I have found so far seem applicable to what I am trying to do. Most of the answers either refer back to this: class not within type bounds or they suggest using wildcards which is not an option here.
When I try to compile, I get the following error:
[uberCompile] BrandDto.java:10: error: type argument T#1 is not within bounds of type-variable T#2
[uberCompile] public class BrandDto<T extends SubCollectionDto> implements IBrand<T> {
[uberCompile]
[uberCompile] where T#1,T#2 are type-variables:
[uberCompile] T#1 extends SubCollectionDto declared in class BrandDto
[uberCompile] T#2 extends ISubCollection declared in interface IBrand
My class structure looks like this:
interface IBrand<T extends ISubCollection>
interface ISubCollection
class Brand<T extends SubCollection>
extends Entity
implements IBrand<T>
class SubCollection
extends Entity
implements ISubCollection
The generated DTO classes look like:
class SubCollectionDto
implements ISubCollection
class BrandDto<T extends SubCollectionDto>
implements IBrand<T>
I'm really racking my brain trying to understand what I am doing wrong here. Any help would be greatly appreciated.
I think I finally figured it out. It was actually a classpath issue that had nothing to do with the generics. When I originally set up the DTO classes they were under the 'src' directory. I later moved them into a different directory, but apparently the old folder never got removed. So eclipse was looking at the current, correct set of files while ant was looking at the old directory. No idea why that was causing the error message I saw, but it is working now.
I have the following class:
public class Blub extends AbstractPreloadDefinition<AddressmasterModel>
The javac compiler gives me the following error:
Error:(15, 79) java: type argument AddressmasterModel is not within
bounds of type-variable T
AbstractPreloadDefinition looks as follows:
abstract class AbstractPreloadDefinition<T extends PersistedEntity<?>> implements PreloadDefinition<T>
and AddressmasterModel looks as follows:
public abstract class AddressmasterModel<V extends VoucherModel> implements Serializable, Auditable, PersistedEntity<Integer>, Comparable<AddressmasterModel<V>>
So, AddressmasterModel implements PersistedEntity. Where's the error? I can't find it :/
I'm using IntelliJ 2017.1 and javac as compiler. If I switch to eclipse as compiler, this error is gone...
I think you need to extend PersistedEntity<Something> and not PersistedEntity. This works:
class Blub extends AbstractPreloadDefinition<AddressmasterModel<VoucherModel>>
I have two inner classes and a method:
protected <A extends Obj1> void a(P<A> p)
{}
private static class P<Z extends Obj1>
{}
private static class Obj1
{}
It's compiling fine, but when I try in Eclipse Mars to change the method a's signature by giving it a second attribute this way
gives the following error:
Bound mismatch: The type A is not a valid substitute for the bounded
parameter <Z extends Test.Obj1> of the type Test.P<Z>
Now actually I have two questions about this. Why is this behavioural difference and what did I do wrong?
Strangely when I modify manually a to this:
protected <A extends Obj1> void a(P<? extends A> p)
{}
and try to change the signature the previously decribed manner I don't get that error. I have a feeling that this may be a bug either in Java or Eclipse, but don't really know where to start seaching. so I give you their versions too if it helps:
Eclipse Mars.2 (4.5.2)
Java 1.8.0.77
UPDATE:
So I've tried more different versions of Eclipse and Java 8, but the result is the same.
When I compile following code in Eclipse - there are no any errors.
There is only one warning:
SomeDerivedAbstractClass is a raw type. References to generic type
SomeDerivedAbstractClass should be parameterized
I tested this code in the newest Eclipse Indigo(3.7.1).
But there is following error when I tried to compile this code by javac:
SomeConcreateClass.java:1: ISomeBaseInterface cannot be inherited with different arguments: <java.lang.Object> and <>
public class SomeConcreateClass
^
1 error
I compiled this code suing Java 5 and Java 6. In both cases there is error.
What is wrong in this code?
public class SomeConcreateClass
extends SomeDerivedClass
implements ISomeInterface
{}
class SomeDerivedClass<T>
extends SomeAbstractClass<Object>
implements ISomeInterface
{
}
abstract class SomeAbstractClass<T>
implements ISomeBaseInterface<T>
{
}
interface ISomeInterface extends ISomeBaseInterface<Object>
{}
interface ISomeBaseInterface<T>
{
}
But following code does not compile either in Eclipse or by javac:
public class SomeConcreateClass
extends SomeAbstractClass
implements ISomeInterface
{}
abstract class SomeAbstractClass<T>
implements ISomeBaseInterface<Object>
{}
interface ISomeInterface extends ISomeBaseInterface<Object>
{}
interface ISomeBaseInterface<T>
{}
javac:
SomeConcreateClass.java:1: ISomeBaseInterface cannot be inherited with
different arguments: and <> public class
SomeConcreateClass
^ 1 error
Eclipse:
The interface ISomeBaseInterface cannot be implemented more than once
with different arguments: ISomeBaseInterface and
ISomeBaseInterface
So - is it a bug in Eclipse?
Is it the same bug as https://bugs.eclipse.org/bugs/show_bug.cgi?id=81824 ?
ONE MORE UPDATE:
This code compiles without errors both by javac and Eclipse:
public class SomeConcreateClass
extends SomeDerivedClass
implements ISomeInterface
{}
class SomeDerivedClass
extends SomeAbstractClass<Object>
implements ISomeInterface
{}
abstract class SomeAbstractClass<T>
implements ISomeBaseInterface<T>
{}
interface ISomeInterface extends ISomeBaseInterface<Object>
{}
interface ISomeBaseInterface<T>
{}
There is only one difference: SomeDerivedClass is not parameterized.
I do not understand how does this influence on ISomeBaseInterface.
AND ONE MORE UPDATE:
I checked code from the first example in IntellijIDEA - this IDE shows error.
But I think it uses different approach for compilation than Eclipse.
Something<> is NOT the same as Something<Object> (even though it might seem like that is reasonable).
SomeAbstractClass<T> implements ISomeBaseInterface<T>, and SomeAbstractClass<> implements ISomeBaseInterface<> So when you use SomeDerivedAbstractClass<> (in SomeConcreateClass), you're asking the class to implement both ISomeConcreateInterface (that is, ISomeBaseInterface<Object>) and ISomeBaseInterface<> at the same time, which it cannot do.
You might want to use SomeDerivedAbstractClass<?>, I think.
i have compiled HTML page using XMLC jar file command..
java org.enhydra.xml.xmlc.commands.xmlc.XMLC -d \core\model\template -class core.model.template.patientPrescriptionsHTML \\core\\model\\template\\PrePrintPrescription.html
it propogate error like
patientPrescriptionsHTML.java:17: core.model.template.patientPrescript
ionsHTML is not abstract and does not override abstract method renameNode(org.w3
c.dom.Node,java.lang.String,java.lang.String) in org.w3c.dom.Document
public class patientPrescriptionsHTML extends org.enhydra.xml.xmlc.html.HTMLObje
ctImpl implements org.enhydra.xml.xmlc.XMLObject, org.enhydra.xml.xmlc.html.HTML
Object {
^
1 error
Error: compile of generated java code failed
please suggest...
In
class A extends B implements C {
}
A must implement all abstract methods from B and C (because C is an interface, all of C's methods count implicitly as abstract.)
Unless, of course, A itself is abstract.