What is the difference between implicit and explicit casting? Why does s = s + 1 fail but s += 1 compile?
Short answer
Converting from a smaller to a bigger type (widening) is automatic; bigger to smaller (narrowing) needs a cast (int) x and can lose data.
3 points to say:
(byte) 130gives-126,(int) 3.99gives3.short + 1becomesint, sos = s + 1fails.s += 1casts implicitly, so it compiles.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.