r/badcode • u/646c726f576f6c6c6548 • Apr 07 '21
java Apparently Java can only handle 255 parameters in a constructor...
4.0k
Upvotes
r/badcode • u/646c726f576f6c6c6548 • Apr 07 '21
730
u/echosalik Apr 07 '21
Meaning someone wrote a constructor with 255 parameters? ... Why?
27
u/_grey_wall Apr 07 '21
Submit a change request to oracle for the next version of Java
11
u/[deleted] Apr 07 '21
I really want to know what those 255 parameters are ? Haha, he managed to overflow the Java constructor . Under what possible scenario would you be needing more than 255 Params , I am interested
5
u/StealthMonkey27 Apr 07 '21
Now this is the content I’m subbed for. Horrifying.
4
u/KemmLK Apr 07 '21
Holy mother of god...how and why?
4
u/jarfil Apr 07 '21 edited May 12 '21
CENSORED
631
u/markand67 Apr 07 '21
I remember a friend of mine also hit the limit of columns in one MySQL table because of previous coworkers, total insanity.
203
u/bleachboy1209 Apr 07 '21
You can pass more paramters if you use json. 255 is for Noobs . Let's go to 25000
2
u/Fractal_Unreality Apr 07 '21
Ever hear of a struct
59
u/PhoenixPaladin Apr 07 '21
I had no idea of this, purely because no one would ever do this
101
u/[deleted] Apr 07 '21
I believe java even has a limit to 255 local variables (since those are stored in the local variable array which is 255 elements long, if I remember that correctly)
64
u/Siggi_pop Apr 07 '21
What a strange number 255, why not round up to 300 /s
61
u/ChroniclesOfLormere Apr 07 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
14
u/szescio Apr 07 '21
"255 parameters ought to be enough for everybody" -Bill Gates
15
u/__Ambition Apr 07 '21
Yeah, its because the JVM uses unsigned byte sized op codes, each opcode can represent upto 255 different numbers. Since function parameters are are actually just numeric indices into an array at runtime (the JVM stack), you can only have upto 255 params.
6
u/h-hub Apr 07 '21
A way to implement a monolith using just one function. Omg
1
u/NoMansSkyWasAlright Apr 07 '21
[desire to know more intensifies]
3
u/BongarooBizkistico Apr 07 '21
Monster
3
u/LeCrushinator Apr 07 '21
This reminds me of the time that I found out that Visual Studio 2008 wouldn't let you put breakpoints past line #65,536 on a file.
1
u/CodersCrux Apr 07 '21
what is this what have you done
2
u/Sugiruu Apr 07 '21
For some reason I learned that at school
2
u/Lothrazar Apr 07 '21
More than 10 should be illegal lol
2
u/R4ttlesnake Apr 07 '21
POV: you're deep in the shitter in some branch of physics but you have no idea how to code
2
u/lofru Apr 07 '21
You made me laugh more than I imagined... really thank you😂🙏🏼
2
u/nrith Apr 08 '21
I really want to see this full constructor.
2
u/Shadow_Being Apr 10 '21
wow i just learned something new.
2
u/CopperyMarrow15 Jul 01 '21
"What the hell happened here?"
1
u/DinoRex6 Apr 07 '21
Functions with variable amount of parameters would also hit that limit right?
1
u/lockieluke3389 Apr 07 '21
There’s always a way to bypass it, I believe!
1
u/prtkp Apr 07 '21
Refactor into a huge POJO
1
u/Perturbatoor Apr 07 '21
I have an example where having more than 255 fields is pretty common:
if you deal with Hadoop, having so many fields (> 255) in table is a normal thing.
and Apache Spark, which can be used to process them, has a class: Dataset[T] in scala or Dataset<T> in java (consider it as pandas dataframe) where you can subsitute T with a structure of the table - usually a scala case class: case class MyStructure(field_name_A: String, field_name_b: Int, ...) or java class, which in that case expected to have more than 255 filelds in constructor.
1
u/[deleted] Apr 07 '21
Son, I am disappoint
1
u/R3D3-1 Apr 07 '21
After reading comments on this post, I consider finding a new job...
1
u/poyat01 Apr 07 '21
I feel like this should be r/badlanguage
1
u/cormac596 Apr 08 '21
no
1
u/Rajarshi1993 Apr 08 '21
Just put some class objects as arguments to the constructors. Each of them can have 32 arguments in their own constructors and hold them as public fields.
1
u/nguepi Apr 08 '21
255 params in the constructors? Is that legal? Sounds to me like a clean code rule being violated.
1
u/sanglesort Apr 16 '21
w-why did you have so many??
1
u/Nilstrieb Apr 18 '21
arrays are also listed to 255 dimensions.
1
u/MalkienShur May 07 '21
Really you hit the limit? Please kill the one who make you do the constructor hahahaha
1
u/Garegin16 Jun 19 '21 edited Jun 19 '21
If having more than 10 params is “bad”. Then why does the language allow it?
It’s like that scene from King of Queens. The wife complains that Doug’s order of jambalaya was ridiculous. He responds “If it’s ridiculous, they shouldn’t put it on the menu”.
1
u/[deleted] Aug 23 '21
makes total sense
1
u/sammy-taylor Dec 03 '22
Open/Closed principle. Closed for modification, open for EXTEEEEEEEEENSIIIOOOOON
1
u/Kotentopf Apr 07 '21
Lol, even T-SQL procedures can have more. About 2100
0
u/[deleted] Apr 07 '21
[deleted] — view deleted comment