constants

Why are some constants public and other private in an Android library code

房东的猫 提交于 2019-12-23 02:22:41
问题 Problem Why some constants are under the public modifier while some other private ? Are those under public can be called from applications that use the library? If so, how to call the constant from an app, is it like this: CertainLibraryClass.ActivityResultCode.CODE_A ? Code public class CertainLibraryClass { public class ActivityResultCode { public static final int CODE_A = 0X02; public static final int CODE_B = 0X03; public static final int CODE_C = 0X04; } public class VersionCode {

Assign a define constant to const char * in C

白昼怎懂夜的黑 提交于 2019-12-22 18:23:42
问题 I'm not entirely sure which is the right way to assign a constant to a const char * . Are both ways okay? #define MSG1 "My Message #1" #define MSG2 "My Message #2" #define MSG3 "My Message #3" const char *opt1 = NULL; const char opt2[20]; switch(n){ case 1: opt1 = MSG1; // or should it be: strcpy(opt2, MSG1); break; case 2: opt1 = MSG2; // or should it be: strcpy(opt2, MSG2); break; case 3: opt1 = MSG3; // or should it be: strcpy(opt2, MSG3); break; } // ... printf("%s", optX); 回答1: opt1 =

Is a global PHP CONSTANT available inside of a Class file?

纵然是瞬间 提交于 2019-12-22 08:04:18
问题 Is a global PHP CONSTANT available inside of a Class file? define('SITE_PATH', 'C:/webserver/htdocs/somefolder/'); Then in my class file I try this public $debug_file = SITE_PATH. 'debug/debug.sql'; This does not seem to work though, Parse error: parse error, expecting ','' or ';'' in C:\webserver\htdocs\somefolder\includes\classes\Database.class.php on line 21 回答1: You cannot have an expression in a class declaration. I would suggest passing the path in: public function __construct($path) {

If the constant interface anti-pattern is such a crime, why does Swing do it?

蓝咒 提交于 2019-12-22 05:03:23
问题 I was making a swing application, and realized I had a handful of classes that needed access to the same set of constants. I couldnt bring myself to declare one the primary holder of them and place them all in there and have the others reference it; I thought, hey, I'll just have them all inherit from some common place, but Java doesnt do multiple inheritence, BUT I can put infinity interfaces on things. So the idea came to me to dump them all into an interface (it's true, it just naturally

PHP: constant as variable in function

送分小仙女□ 提交于 2019-12-22 04:49:18
问题 I'm trying to use constant as a function paramter, is it possible to check type of this constant. Example of what I want: class ApiError { const INVALID_REQUEST = 200; } class Response { public function status(ApiError $status) { //function code here } } USE: $response = new Response(); $response->status(ApiError::INVALID_REQUEST); This shoud check that given $status is constant of class ApiError. Is something like this possible? 回答1: As the others mentioned, there is no generic solution. But

PHP Reflection: get constant's doc comment

倾然丶 夕夏残阳落幕 提交于 2019-12-21 19:58:28
问题 It is easy to retrieve the doc comment for methods and properties. But what about constants? There is no ReflectionConstant class which would allow me to call getDocComment() on them. It's possible to get the list of constants and their values as strings using ReflectionClass::getConstants but that's all. Is there a workaround? 回答1: To my best knowledge there is no built-in function or class that allows you to retrieve class constant doc comments. However, you can use token_get_all(

Details of what constitutes a constant expression in C?

徘徊边缘 提交于 2019-12-21 09:07:31
问题 C defines at least 3 levels of "constant expression": constant expression (unqualified) arithmetic constant expression integer constant expression 6.6 paragraph 3 reads: Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated. So does this mean 1,2 is not a constant expression? Paragraph 8 reads: An arithmetic constant expression shall have arithmetic type and shall

(In Ruby) allowing mixed-in class methods access to class constants

无人久伴 提交于 2019-12-21 07:31:10
问题 I have a class with a constant defined for it. I then have a class method defined that accesses that class constant. This works fine. An example: #! /usr/bin/env ruby class NonInstantiableClass Const = "hello, world!" class << self def shout_my_constant puts Const.upcase end end end NonInstantiableClass.shout_my_constant My problem arises in attempting to move this class method out to an external module, like so: #! /usr/bin/env ruby module CommonMethods def shout_my_constant puts Const

(In Ruby) allowing mixed-in class methods access to class constants

不羁的心 提交于 2019-12-21 07:31:10
问题 I have a class with a constant defined for it. I then have a class method defined that accesses that class constant. This works fine. An example: #! /usr/bin/env ruby class NonInstantiableClass Const = "hello, world!" class << self def shout_my_constant puts Const.upcase end end end NonInstantiableClass.shout_my_constant My problem arises in attempting to move this class method out to an external module, like so: #! /usr/bin/env ruby module CommonMethods def shout_my_constant puts Const

What are your thoughts on method scoped constants?

橙三吉。 提交于 2019-12-21 06:48:43
问题 For example: public void doSomething() { final double MIN_INTEREST = 0.0; // ... } Personally, I would rather see these substitution constants declared statically at the class level. I suppose I'm looking for an "industry viewpoint" on the matter. 回答1: My starting position is that every variable or constant should be declared/initialized as close to it's first use as possible/practical (i.e. don't break a logical block of code in half, just to declare a few lines closer), and scoped as