Objective C defining UIColor constants

A UIColor is not mutable. I usually do this with colors, fonts and images. You could easily modify it to use singletons or have a static initializer. @interface UIColor (MyProject) +(UIColor *) colorForSomePurpose; @end @implementation UIColor (MyProject) +(UIColor *) colorForSomePurpose { return [UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]; } @end

In Java, can I declare a HashMap constant?

Yes, it can be a constant. You should declare your HashMap instance as follows: class <class name> { private static final HashMap<Integer, String> tensNumberConversion = new HashMap<>(); static { tensNumberConversion.put(2, “twenty”); tensNumberConversion.put(3, “thirty”); tensNumberConversion.put(4, “forty”); tensNumberConversion.put(5, “fifty”); tensNumberConversion.put(6, “sixty”); tensNumberConversion.put(7, “seventy”); tensNumberConversion.put(8, “eighty”); tensNumberConversion.put(9, “ninety”); } } However, this is only a constant reference. While … Read more

C++ const in getter [duplicate]

There is a huge difference between the two ways. const bool isReady() The code above will return a const bool, but it does not guarantee that the object will not change its logic state. bool isReady() const This will return a bool, and it guarantees that the logic state of your object will not change. … Read more

Is ‘const’ necessary in function parameters when passing by value? [duplicate]

First, it’s just an implementation detail, and if you put const there, don’t put it in the declaration set (header). Only put it in the implementation file: // header void MyFunction(int age, House &purchased_house); // .cpp file void MyFunction(const int age, House &purchased_house); { … } Whether or not a parameter is const in a … Read more

Any method to get constant for HTTP GET, POST, PUT, DELETE? [duplicate]

If you are using Spring, you have this enum org.springframework.web.bind.annotation.RequestMethod public enum RequestMethod { GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; } EDIT : Here is the complete list of constants values in Java 6 You can see that some of those are available in the class HttpMethod but it contains less values than … Read more