Is it possible to create a new Custom Conditional Statement in java.Here i am planning to create a new custom component for the switch statement to give better performance. The custom Switch control which i am planning to create will have only integer operators: example:int i = SOMEVALUE;Switch(i){Case 1: //Some StatementBreak;Case 2: //Some StatementBreak;Case 3: //Some StatementBreak;............Case 10000000: //Some StatementBreak;Default://Some StatementBreak;}According to my knowledge the Switch condition will check in a particular order. If the actual value of the i variable is 9999999 then it has to check the case for 9999999 times but if we check it with some algorithms similar to binary search then its performance will be improved. Am I Right ?? If right then why don't we add this functionality to our programming language ?So why don't we create a Custom Conditional Statement something like OrderedIntegerSwitch statement , in which the value passed inside that switch should be an integer.
how to create a new Custom Conditional Statement in programming language
programming languages;performance;custom control
According to the JVM spec, a switch statement can be compiled to the bytecode instructions tableswitch or lookupswitch, depending on wether the cases of the switch are sparse.tableswitch is O(1), while lookupswitch seems to be O(log n) (I guess it uses a binary search)If you are curious about what instruction is chosen by your compiler for your piece of code, just decompile the bytecode and see if you find one instruction the other.