The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

0

Take a look at How to: Specify an Alternate Element Name for an XML Stream. Although it is more code, I would use the mentioned XmlAttributeOverrides like so public static string GetXml<T>(T instance, string sourceName = "InnerObject") where T : class { var wrapper = new DocumentElement<T>(instance); var writer = new StringWriter(); ...


2

Definitely not one of my proudest answers... You can delegate the work of casting to another function fun <T> Pair<*,*>.validate2(lambda: (T, T)->Boolean) = lambda(first as T, second as T) In your validateHelperclass you can call this function: fun <T> validateRangeHelper(pair: Pair<T,T>): Boolean = when(pair.first) { is Int ...


1

If this is a comment theme throughout your code I would say to make an IArgument interface that would manage your object parameters. But if this is the only time you are dealing with these obj parameters, I would say pass the arguments of IsSatisfied in as generic objects and let IsSatisfied worry about ordering the arguments by type: void IsSatisfied(...


2

You could try something like the following in The Animal Class: @Override public boolean equals(Object obj) { Animal animal = null; if(obj == null || this ==null) { return false; } if(obj instanceof Animal) { animal = (Animal) obj; } if(this.name.equals(animal.getName())) { return true; ...


2

Your code is good, but some improvements could be made. Here are my suggestions: 1) Use lowercase for first letter of variable Example: BrandService BrandService; rename to: BrandService brandService; 2) Use Lombock @Getter @Setter @Slf4j @*Constructors and so on. It will make code clean and readable 3) Use ControllerAdvise for global error handling: ...


Top 50 recent answers are included