29

So I found this in the code:

Inet4Address.getByAddress (new byte[] {0x7f,0x00,0x00,0x01})

It's localhost. Why the actual fuck would you declare 127.0.0.1 as a fucking byte array!

Comments
  • 15
    Code masturbation
  • 9
    Because IP addresses are in fact numbers, and subnet calculations are made by bitmasking the IP address and the network mask.

    Storing them as strings is only helpful for readability, and it's pretty trivial to turn them into strings if you need to print them somewhere.

    BTW, wouldn't it be correct to use decimal notation instead of hexadecimal to make it more readable?

    Inet4Address.getByAddress(new byte[] {127, 0, 0, 1})
  • 3
    Because IPv4 addresses consist of four seperate octals.
  • 1
    Why not?
  • 2
    Readability > I'm smart enough to count in binary.

    I agree with your wtf
  • 0
    @mrrmc *hexadecimal
  • 0
    @filthyranter my point exactly :)

    Thanks :D
  • 5
    I also wrote that shit.
    It's the only way that doesn't force you to write a fucking try-catch block because you may have misspelled the address. Or that doesn't desperately try to resolve the string to the nearest DNS server while you just wanted to have a fucking localhost address.
    Oh, and because the only-fucktard factory method accepts a byte array, you cannot just put decimal numbers because they would be treated as signed integers, forcing you to add a cast on each number. Hex literals are fine.
    That's Java, folks🤷‍♂️
  • 1
    @redundandundant

    I'm sorry. That's a fucking hilarious username. If I was a woman...
  • 2
    @rant1ng redundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundandundan...

    java.lang.StackOverflowError
  • 0
  • 5
    Inet4Address.getLoopbackAddress()
  • 0
    Yeah doing it this way is so much easier. I had to make an assignment that did subnet calculation, and being able to bitwise shift made life so much easier.
  • 0
    He was drunk.
  • 0
    I respect people who manipulate shit in hexadecimal
Add Comment