2

Final class in java means its not extendable by any other class. How do we do it in hybris while defining data-model in -Items.xml ?

Arun Gowda
  • 2,721
  • 5
  • 29
  • 50

1 Answers1

1

SAP Hybris platform does not support generation of the final data-model classes OOTB (Out Of The Box). You cannot override that mechanism, but you are allowed to modify generated class located in the src directory. If you want a final data-model class (e.g. Foo), you can manually add this modifier.

<itemtypes>
    <itemtype code="Foo" jaloclass="org.example.Foo">
        <attributes>
            <!-- attributes -->
        </attributes>
    </itemtype>
</itemtypes>

File structure:

  • src/org/example/Foo ← you can mark this class as final
  • gensrc/org/example/GeneratedFoo ← you cannot modify this class

(class Foo extends GeneratedFoo)

All extensions with types which extend Foo will fail during build phase.


SAP Hybris platform allows only to set an abstract modifier by using an abstract attribute equal to true:

<itemtypes>
    <itemtype code="Foo" abstract="true">
        <attributes>
            <!-- attributes -->
        </attributes>
    </itemtype>
</itemtypes>
agabrys
  • 8,728
  • 3
  • 35
  • 73
  • Those generated files are placed in the `src` directory to allow developers to add additional behavior. Whether a modification is good or bad depends on the type of change. I think that adding `final` modifier is not a good change, but it is possible. – agabrys Oct 07 '17 at 15:45