Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข13mo agoโ€ข
25 replies
Steadhaven

Extend/Inherit java class - how to?

I have a repo with some kind of config in the style of a YAML file... As an example its something like this:
something:
   calling-birds: four
   french-hens: 3
   golden-rings: 5
   partridges:
     count: 1
     location: "a pear tree"
   turtle-doves: two

I wanted to extend it to deal with different system:
something:
  system: AfricanBirds
     calling-birds: four
     french-hens: 3
     golden-rings: 5
     partridges:
       count: 1
       location: "a pear tree"
     turtle-doves: two
  system: EuropeanBirds
     calling-birds: five
     french-hens: 2
     golden-rings: 3
     partridges:
       count: 2
       location: "an oak tree"
     turtle-doves: one

Its just an example, doesn't make sense necessarily.

Now in Java, in another repo, I want to account for this indentation/nested change...
class BirdProperty {
  String calling-birds;
  Integer french-hens;
  List[] partridges;
  //...etc
}

How do I correct myself now? A lot of code and test use BirdProperty, but now theres two "systems" of them and I need to somehow also indent/nest my java code with some inheritentance or something.
Keep in mind the above Java and YAML code is probably wrong in itself, but this is sort of what the code and yaml change was from memory.
Was this page helpful?