• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Generic method

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on an application that invokes several different downstream 3rd party web services. Each web service has its own ServiceError class (tool generated javax.xml.bind.annotation class).

Processing errors from each different service invocation is the same so I wrote this generic method:



Is there a better way to write this code?

ServiceError1 and ServiceError2 come from different package and do not implement the same/any interface. These classes are tool generated and I cannot manually change them.

Thank you!

 
Sheriff
Posts: 22700
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code isn't great, because each time a new generated class is added, you need to add a new else-if clause to that method. If you forget to then nothing will happen. Perhaps adding an else clause that throws an exception if none of the clauses matches can at least help you find such occurrences instead of failing very silently.

However, this is tedious and error prone. Can you modify the code generation code to add an interface? If not, can you check if you can generate this method somehow?
 
Something must be done about this. Let's start by reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic