Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AS400DataType: use generics #71

Open
NicolaIsotta opened this issue May 23, 2023 · 2 comments
Open

AS400DataType: use generics #71

NicolaIsotta opened this issue May 23, 2023 · 2 comments
Labels

Comments

@NicolaIsotta
Copy link
Contributor

eg. AS400ZonedDecimal would look like this:

public class AS400ZonedDecimal implements AS400DataType<BigDecimal> {
    public byte[] toBytes(BigDecimal javaValue) {...}
    public int toBytes(BigDecimal javaValue, byte[] as400Value) {...}
    public int toBytes(BigDecimal javaValue, byte[] as400Value, int offset) {...}
    public BigDecimal toObject(byte[] as400Value) {...}
    public BigDecimal toObject(byte[] as400Value, int offset) {...}

Not sure about binary compatibility. Maybe leaving toBytes methods without generics could avoid breaking retrocompatibility?

@NicolaIsotta
Copy link
Contributor Author

After a second check, this may not be possible.
AS400ZonedDecimal may return a Double instead of a BigDecimal if _useDouble is true

/**
* Converts the specified IBM i data type to a Java object.
* @param as400Value The array containing the data type in IBM i format. The entire data type must be represented.
* @param offset The offset into the byte array for the start of the IBM i value. It must be greater than or equal to zero.
* @return The BigDecimal object corresponding to the data type.
**/
public Object toObject(byte[] as400Value, int offset)
{
if (useDouble_) return new Double(toDouble(as400Value, offset));

@ThePrez
Copy link
Member

ThePrez commented May 26, 2023

I think you're right. Generics aren't the answer here.

What we need is simply better method signatures. While we can do that in a way that maintains source compatibility, it breaks binary compatibility and will result in NoSuchMethodErrors if we don't keep the existing ones intact. Even on a major semver upgrade, I don't feel comfortable doing that until the semver strategy is more adopted by the user community.

We could introduce a second set of functions with proper typesafety, but something just doesn't seem right about that.

It's unfortunate that the AS400DataType interface has Object signatures. I feel like we need to rethink the design about all data type implementations as a whole.

This is a great issue and one that I'd like to keep open for discussion. Unfortunately, I'm not seeing a good answer right now. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants