How to make switch case accept multiple data types in Java?
While using Java's switch case, it excepts only char and int, but I want to provide string cases. How to make this possible? ...
While using Java's switch case, it excepts only char and int, but I want to provide string cases. How to make this possible? ...
Given that it's valid to write a = b = c = 2; It would also be nice, rather than bool allTwo = a == 2 && b == 2 && c == 2; to instead write bool allTwo = a == b == c == 2; But I can't since a == b evaluates to a boolean which can't then be compared to an integer. Is there a language-design reason it has been implemented this w...
I came across the Python with statement for the first time today. I've been using Python lightly for several months and didn't even know of its existence! Given its somewhat obscure status, I thought it would be worth asking: What is the Python with statement designed to be used for? What do you use it for? Are their any gotchas ...
I am searching for an overview of the features of Clojure that are coming from other languages than Common Lisp. For example: STM: language X, Y and Z Your input is welcome! ...
I have a lot of methods for logging, like logSomeAction, logAnotherAction etc. Now I want all these methods make a small pause after printing messages (Thread.sleep). If I do it manually, I would do something like this: //before: public static void logSomeAction () { System.out.println (msg(SOME_ACTION)); } //after: public static ...
For instance String s = "Hello" + " World"; I know there are two strings in the pool "Hello" and "World" but, does: "Hello World" go into the string pool? If so, what about? String s2 = new String("Hola") + new String(" Mundo"); How many strings are there in the pool in each case? ...
Possible Duplicate: Hidden Features of Java What are some Java language features or Java related tools that you were embarrassed to find that you didn't know about? Examples for me are: jmap RuntimeException Please post things every Java programmer should know about, be they language features, tools, or facts about how the...
Let's say I have a function def odd_or_even n if n%2 == 0 return :even else return :odd end end And I had a simple enumerable array simple = [1,2,3,4,5] And I ran it through map, with my function, using a do-end block: simple.map do |n| odd_or_even(n) end # => [:odd,:even,:odd,:even,:odd] How could I do this with...
C and many other languages have a conditional (aka ternary) operator. This allows you to make very terse choices between two values based on the truth of a condition, which makes expressions, including assignments, very concise. I miss this because I find that my code has lots of conditional assignments that take four lines in Python: ...
This works: #include<cstdio> class A{ public: A(int a):var(a){} int var; }; int f(A obj) { return obj.var; } int main() { std::cout<<f(23); // output: 23 return 0; } while this doesn't: #include<cstdio> class A{ public: A(int a, int b):var1(a), var2(b){} int var1, var2; }; int f(A obj) { return (...
I was told to avoid using features of C++ like these as it makes it difficult to port the code to other compilers. The example I was given was using #ifdef instead of #pragma once in my header files. ...
Possible Duplicates: Is there any advantage of being a case-sensitive programming language? Why are many languages case sensitive? Something I have always wondered, is why are languages designed to be case sensitive? My pea brain can't fathom any possible reason why it is helpful. But I'm sure there is one out there. And ...
I have recently begun working at a company wherein there are very few (2-3) programmers and many more engineers. As a result, the default language of choice has become VB.net. I look at some of the math-intensive portions of the programs that have been written thus far and I'm certain that these portions could be improved considerably if...
I have heard it said that Objective c is a 'simple' language, i.e. in terms of it's language features. It's really the only language that I know but I did a bit of Java before and, in terms of language features, they seem to be pretty close. I have never touched C++. Is there more features to C++ compared with Objective-C and if so, is ...
What is the most efficient way to convert numeric amount into English words e.g. 12 to twelve 127 to one hundred twenty-seven ...
C99 still isn't supported by many compilers, and much of the focus is now on C++, and its upcoming standard C++1x. I'm curious as to what C will "get" in its next standard, when it will get it, and how it will keep C competitive. C and C++ are known to feed on one another's improvements, will C be feeding on the C++1x standard? What ca...
What is the name of the character at the end of each of these lines? Dim _int As Integer = 1I Dim _short As Short = 1S Dim _long As Long = 1L Dim _single As Single = 1.0F Dim _double As Decimal = 1D I've always called these "type specifiers". I assume that's incorrect as I'm unable to find the official documentation using this term. I...
I came across a C# language feature today courtesy of ReSharper, the ?? operator. This helped make the code even more concise than my initial attempt. See below for iteration in improving lines/length/readability of code. A first attempt could be something like.. if (usersEmail == null) userName = firstName; else userName = usersEm...
I'm looking for things like Dynamic typing, Static Typing, Weak Typing, and Strong Typing. As well as OO features like polymorphism, inheritance, nested classes, inner classes, abstract classes, pure virtual functions. Also, things like reflection, static binding, dynamic binding, etc. However, I'm not really looking for things like ...
I've been playing with Clojure recently and it got me thinking... What are you looking for from a programming language before you will consider using it out of choice? What is it about a language that will make you take notice and look into it? Things that immediately sprang to my mind are the tools available. I find having a very good...