amelentev / java-oo

Java Operator Overloading
http://amelentev.github.io/java-oo/
268 stars 31 forks source link

Cannot yet instantiate directly from String #56

Closed PowerUser1234 closed 6 years ago

PowerUser1234 commented 6 years ago

BigDecimal a = "1";

Note: Injecting OO to javac8 C:\Users\User\Desktop\Arbitrary Numbers\src\ArbitraryNumbers\Example.java:48: error: incompatible types: String cannot be converted to BigDecimal BigDecimal a = "1"; 1 error

amelentev commented 6 years ago

there is no BigDecimal.valueOf(String) method so it is impossible to convert a String to BigDecimal. but there is valueOf(long) method so BigDecimal a = 1 will work.

see README.md details section:

assignment:

| var = expr | var = VarClass.valueOf(expr) |

if expr is not assignable to var and var is an instance of VarClass and expr has type ExprType and there are static method VarClass#valueOf(ExprType) then var = expr is transformed to var = VarClass.valueOf(expr). example: BigInteger a = 1 is transformed to BigInteger a = BigInteger.valueOf(1)

Maaartinus commented 6 years ago

There's a constructor BigDecimal(String), which could be used - assuming that it's possible to special case standard classes. Is it?

This would be useful for BigDecimal a = "1.1" as there's no long workaround. The double workaround probably works, but it loses precision for some inputs.

PowerUser1234 commented 6 years ago

Yes, true, true, all true. I simply meant to imply for the sake of both versions of the syntax.

BigDecimal d = new BigDecimal("3")

Java-OO might like the option

BigDecimal a = "1.1";

that's all.

The other thing, is that the included MathContexts all have RoundingMode.HALF_EVEN, when they should probably start with RoundingMode.DOWN, I do believe even if they are negative or positive.

I've got any number of java projects ready to go, they just need the operation of the plugin finished (even if not for the netbeans plugin version, which would be super as well).

I would contribute myself, but I too have limited options at the immediate time being.

It seems that you have +,-,* overridden operators going.

My previous email was likely just too much information.

Unless Oracle does anything involving operators in Java 11 with its Valhalla Value Types, which may or may not have anything to do with operators.

I would exhort you or anyone else involved to finish the compiler version of Java-OO. With both versions finished, it will be more than a force to be reckoned with, it will be THE WAY to do java for very many people, globally.

/ needs to be implemented, but also involving the old way of affecting the answer by different MathContext, RoundingMode, Precision, even Scale settings.

% needs to be done, if it hasn't already.

+=, -+, *=, /=, %= should be part of the new Java-OO syntax.

i++, i--, ++i, --i all should be there too!

Are there any other developers on this project other than yourself, Artem?

Do you have their email addresses, so that they could be contacted?

Many, many thanks! The project, even the compiler only version, just needs to be completed, that's all!

Yours Truly and Anonymously,

poweruserm


From: Maaartinus notifications@github.com Sent: Wednesday, 4 April 2018 6:49 AM To: amelentev/java-oo Cc: PowerUser1234; Author Subject: Re: [amelentev/java-oo] Cannot yet instantiate directly from String (#56)

There's a constructor BigDecimal(String), which could be used - assuming that it's possible to special case standard classes. Is it?

This would be useful for BigDecimal a = "1.1" as there's no long workaround. The double workaround probably works, but it loses precision for some inputs.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/amelentev/java-oo/issues/56#issuecomment-378394557, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfogeFINteYQlhUn88jp-S5KWcUhevFpks5tk-BjgaJpZM4TBU_A.

amelentev commented 6 years ago

yes. it is possible to implement this assignment operator overloading using constructors also. But current implementation is already complicated. As a workaround, you can create your wrapper classes and implement valueOf methods using constructors.