Post-compile enhancement sometimes causes error in generic loops: incompatible types found: java.lang.Object: required: Entity

Type: BugVersion: 2.4.0Priority: NormalStatus: ActiveReplies: 2
#1

I have moved from automatic run-time enhancement to explicit post-compile enhancement in an Ant build.xml in a NetBeans web app, and sometimes on editing a file that performs a generic for loop over an @entity type I get a generics error. The generic for loop is: 

for (Steel s: this.steelMaterials.getL_Steel().getEls()) {
 ..
}

Where getEls() here gives:

List<Steel>

This sometimes (only, I don't understand the circumstances) gives this error:

incompatible types
found: java.lang.Object
required: com.example.entity.Steel
        for (Steel s: this.steelMaterials.getL_Steel().getEls()) {

The workaround is to simply clean and build the entire project, which is quite tedious and time-consuming.

I appreciate any feedback on how to address this to improve my development cycle, which is compromised by this.

--- Webel IT Australia, "The Elements of the Web", Specialists in model-based UML, SysML, Enterprise Java, XML, and Drupal CMS web engineering. Dr Darren Kelly, BSc, PhD, https://www.webel.com.au
#2

This rewrite of the generic for loop works but it is inconvenient to have to remove generic loops just because of enhancement:

for (Object os : steelMaterials.getL_Steel().getEls()) {
 if (os instanceof Steel) {
  Steel s = (Steel)os;
  // do something with "cast" Steel (no pun intended)
 }
}
--- Webel IT Australia, "The Elements of the Web", Specialists in model-based UML, SysML, Enterprise Java, XML, and Drupal CMS web engineering. Dr Darren Kelly, BSc, PhD, https://www.webel.com.au
#3

Could you please provide a simple console test case that demonstrates this issue?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login