Skip to content

Java Generics : <T extends Number> T Sum(List<T> data) #1

Open
@zwrawr

Description

The abstract number class does not define any functions for numeric operations and there is not interface for it.

The only solution I've found online that doesn't involve a case for each type is converting the Number to it's string representation(serializing it). Then using BigDecimal to deserialize it, and adding the two big decimal numbers together. And finally converting back to it's original type. Which seems like a very 'hacky' and easily breakable solution.

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions