funny Java

Feb. 4th, 2010 11:04 am
juan_gandhi: (Default)
[personal profile] juan_gandhi
byte b = Byte.parseByte("80", 16);

throws an exception "value out of range"

very, very smart...

Date: 2010-02-04 07:05 pm (UTC)
From: [identity profile] ygam.livejournal.com
Does it have to be "-80"?

Date: 2010-02-04 07:12 pm (UTC)
From: [identity profile] nowherenoone.livejournal.com
У меня вчера кинуло, когда я "192" запихнул. И её можно понять.
Но "80"???

Date: 2010-02-04 07:21 pm (UTC)
From: [identity profile] nowherenoone.livejournal.com
Ай, 16 просмотрел :)

Date: 2010-02-04 07:20 pm (UTC)
From: [identity profile] taganay.livejournal.com
Ну в принципе её (джаву) можно понять:
static byte MAX_VALUE: A constant holding the maximum value a byte can have, 2^7-1.

Date: 2010-02-04 07:33 pm (UTC)
From: [identity profile] itman.livejournal.com
Да, а никто не обещал, что в байте будет восемь бит!
PS: но причина, конечно же, не в этом, а в том, что в Джаве просто нет беззнаковых числовых типов.
Edited Date: 2010-02-04 07:36 pm (UTC)

Date: 2010-02-05 12:41 am (UTC)
From: [identity profile] ostapru.livejournal.com
А причем здесь беззнаковые?
80 < 127 ? ;)

Date: 2010-02-05 06:27 am (UTC)

Date: 2010-02-04 07:56 pm (UTC)
From: [identity profile] scolar.livejournal.com
Ну, если синтаксис языка допускает
byte b = (byte)0x80;

то не очень понятно, почему бы и не распарсить.

Date: 2010-02-04 08:10 pm (UTC)
From: [identity profile] gaus.livejournal.com
спецификация не позволяет :(

Date: 2010-02-04 08:14 pm (UTC)
From: [identity profile] taganay.livejournal.com
"byte" - это синтаксис, а "Byte" - это уже библиотека.
Хотя синтаксис уродский, согласен.

Date: 2010-02-05 12:42 am (UTC)
From: [identity profile] ostapru.livejournal.com
Но там же вроде "80", а не "0x80"?

Date: 2010-02-05 01:13 am (UTC)
From: [identity profile] ivan-gandhi.livejournal.com
Ну это же не Хаскель. Я ж указываю 16 в качестве основания.

Date: 2010-02-05 09:47 am (UTC)
From: [identity profile] ostapru.livejournal.com
А блин! Доку надо смотреть - думал, что 16 - это типа maxlength.

Date: 2010-02-04 07:37 pm (UTC)
From: [identity profile] itman.livejournal.com
В Джаве байт - это signed char. И типов unsigned просто нет.

Date: 2010-02-04 10:09 pm (UTC)
From: [identity profile] baramin.livejournal.com
ну нет в Java байтов в С-шном понимании. С этим трудно жить, но лучше принять и смириться. На заре истории это казалось благом - тот, кто торгуется за последний бит готов переехать в следующий тип.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
181920 21 222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 23rd, 2025 11:35 pm
Powered by Dreamwidth Studios