r/badcode • • Apr 07 '21

java Apparently Java can only handle 255 parameters in a constructor...

Post image
4.0k Upvotes

249 comments sorted by

View all comments

203

u/bleachboy1209 Apr 07 '21

You can pass more paramters if you use json. 255 is for Noobs . Let's go to 25000

37

u/echosalik Apr 07 '21

You know that Wolf of Wall Street meme, those are rookie numbers, fit pretty appropriately here. Missed opportunity I'd say.

5

u/bleachboy1209 Apr 07 '21

Realised it pretty late. My meme brain is still a rookie

24

u/[deleted] Apr 07 '21

How about you make 255 subclasses each with a constructor of 255 objects, then instantiate them in the constructor

6

u/bleachboy1209 Apr 07 '21

Such a evil comment !

7

u/lachlanhunt Apr 08 '21

JSON is not the most efficient format, though. cause you waste a lot of space on property names and syntax. We have other options like plain comma separated values.

A string in Java can be 231 -1 characters, where a character is a 16 bit code unit, so we have 232 -2 bytes for each of the 255 parameters. Therefore, we can have up to 107,374,182,350 bytes of data (~107GB) passed into a function. Depending on the data being passed in, we could also gzip before passing it in and get even more.

1

u/old_sport92 Jan 01 '22

Why do you give fire to a kid?! Don't give em ideas!

6

u/Gramr_nasi Apr 07 '21

It’s over 9 000 !!!

0

u/[deleted] Apr 07 '21

[deleted] β€” view deleted comment

3

u/[deleted] Apr 07 '21

[removed] β€” view removed comment

5

u/[deleted] Apr 07 '21
                                __
                               /  \      __
   .---.                  _   /   /   _.~  \
   \    `.               / \ /   /.-~    __/
     `\    \              |  |   |/    .-~ __
      \    \             |  |   |   .'--~~  \
       \    \            |  |   `  ' _______/
        \    \           |  `        /
    .--. \    \          |    `     /
    \   `.\    \          \        /
     `\   \     \          `\     (
       \   \     \           > ,-.-.
        \   `.    \         /  |  \ \
         \    .    \       /___| O |O\     ,
      .-. \    ;    |    /`    `^-.\.-'`--'/
      \  `;         |   |                 /
       `\  \        |   `.     `--..____,'
         \  `.      |     `._     _.-'^
          \   .     /         `|`|`
        .-.\       /           | |
        \  `\     /            | |
         `\  `   |             | |
           \     |             | |
          .-.    |             | |
          \  `.   \            | |
           `\      \           | |
             \      \          | |
              _____ :-'~~~~~'-' ;
              /____;``-.         :
             <____(     `.       ;
               ___\     ;     .'
                  /``--'~___.-'
                 /___/^/__/
                /   /' /`/'
                \  \   `\ \
                 `\ \    \ \
                   \ \    \ \
                    \ \    \ \
                     \ \    \ \     ______
                      \ \ ___\ \'~``______)>
                       \ ___ _______ __)>
                   _____\ \'~``______)>
                 <(_______.._______)>

FTFY

2

u/TruVortex_07 Apr 07 '21

huh?

1

u/[deleted] Apr 07 '21

It's ASCII art

→ More replies (2)

5

u/Siggi_pop Apr 07 '21 edited Apr 07 '21

JSON in itself is an object, so that's only 1 parameter!?

7

u/Farsqueaker Apr 07 '21

Serialized JSON as JSON properties. JSeption.

2

u/[deleted] Apr 07 '21

But where's the fun in that?

3

u/bleachboy1209 Apr 07 '21

woooosh!!!

0

u/Siggi_pop Apr 07 '21

What am I missing here??

If you pass a JSON object as parameter to constructor then you have teoretically unlimited wrapped properties i.e. key/value pairs (not parameters) .....but then again....you can do that with any object/reference type, even XML will do the job.

1

u/LeCrushinator Apr 07 '21

I think that was the original comment's joke, that you could have thousands or parameters if you just pass in a json object instead. So your original comment was simply restating that.

-1

u/Siggi_pop Apr 07 '21

I guess JSON threw me off, I mean it's JAVA.... close to everything is an object! Why would anyone introduce an (natively) unsupported datatype like JSON into the mix??

But maybe it adds something to the joke!? I mean JSON is a funnier word rigth!? And also it is funny when people act as they have almost no clue to what they are talking about.

2

u/[deleted] Apr 07 '21

Watchu talking about. The first word in json is java

1

u/Siggi_pop Apr 07 '21

Yeah, the first word (name actually) in JSON is JavaScript. As you know Java is to JavaScript as ham is to hamster! God forbid we confuse those two.

→ More replies (2)

1

u/bleachboy1209 Apr 07 '21

The joke was to propose a worst solution.

1

u/Siggi_pop Apr 07 '21

But it's not even the worst solution!? It's actually a prefered solution to wrap data into a DTO and pass that as parameter....worst solution would be to use up all 255 parameters and then introduce a secondary init method to pass the left over parameters into.

1

u/bleachboy1209 Apr 07 '21

You are right!