|
Hi,
If you have a class member that is static and public. Would you write "static public" or "public static"? I know they are the same. But is there some recommendation / best practice for writing this?
Started by Peter van der Heijden on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
"public static....
I personally would go with public static because it's more important that it's public than, but the concept is the same)
Short version: "public static" is recommended and is far more common.
|
|
A minor point about function declaration keywords in PHP: If you've got a class method that's static, should the static keyword come before or after the visibility keyword ( public , protected , private )? Assuming all your methods, static or otherwise...
Started by dirtside on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
I guess 'public static' is really the most common format in favor of '....
Thanks for the input, guys.
public static
looks correct to me if it's public.
Neither language has this requirement.
Line is completely false.
|
|
Consider this sample class,
class TargetClass { private static String SENSITIVE_DATA = "sw0rdfish"; private static String getSensitiveData() { return SENSITIVE_DATA; } }
When I do this,
import java.lang.reflect.Method; public class ClassPiercing { public...
Started by eradicus on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The point....
Http://java.sun.com/javase/6/docs/api/java/lang/SecurityManager.html
http://java.sun.com/javase/6/docs/technotes/guides/security/permissions.html#ReflectPermission
disabling ReflectPermission should do the trick.
Well, use a SecurityManager.
|
Ask your Facebook Friends
|
In Java I can write:
public final static MyClass foo = new MyClass("foo");
is there an equivalent in C#?
Started by peter.murray.rust on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Think of is readonly :
public static readonly MyClass field = new MyClass("foo");
sealed class.
|
|
When trying to compile my class I get an error:
The constant 'NamespaceName.ClassName.CONST_NAME' cannot be marked static.
at the line:
public static const string CONST_NAME = "blah";
I could do this all of the time in Java. What am I doing wrong? And...
Started by Justin Nelson - jjnguy on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
A const....
From the C# language specification (PDF page 287 - or 300th page of the PDF):
Even though constants are considered static members, a constant declaration neither requires nor allows a static modifier.
Const implies static.
|
|
Hello,
I'm new to C#.Till this moment I used to make every global variable - public static.All my methods are public static so I can access them from other classes.
I read on SO that the less public static methods I have,the better.So I rewrote my applications...
Started by John on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Your question seems like a duplicate of:
http://stackoverflow.com/questions/99688/private-vs-public int pin = 1090; ....
static on the other hand has no relation to the two, because.
With the user having access to should be public.
|
|
So we've all seen the Threading notification on MSDN for many available generic objects:
"Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe."
My question is, what is ...
Answer Snippets (Read the full thread at stackoverflow):
It's still possible to have race conditions in static / shared methods if they touch....
Static methods in general do not access shared state and hence are less likely to run into this problem.
Not access shared state in a thread safe manner.
|
|
It seems to me that non-public top-level classes and static nested classes essentially perform the same tasks when creating a helper class.
A.java public class A { public static main (String[] args) { AHelper helper = new AHelper(); } } class AHelper ...
Started by Stephen on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
But generally, you use a static nested other class in the same file as the....
You cannot do this for anyIn neither example do you have one class per source file .
One difference is that a static nested class can be declared public.
|
|
I figured out how to create a static method that is available everywhere, for example:
UtilLib.as:
package { public final class UtilLib { public static function getTimeStamp():uint { var now:Date = new Date(); return now.getTime(); } } }
I can access ...
Started by Tom on
, 5 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
}
The syntax might be incorrect; import flash.events....
}
you have
public static function writeTimeStamp(messageBox):uint { ...
So instead of
public static function getTimeStamp():uint { ...
Pass in a pointer to your textbox.
|
|
I'm trying to get a real equivalent for Java's public static final in Scala for using TwiP .
Creating a val in an object don't works for me, because it's part of a new generated class Example$.class and TwiP can't access it from class Example.class.
Here...
Started by renfis on
, 4 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You want to use public static final on a variable, as a better solution might be more obvious definition in the companion object creates your public static final variable, and the import declaration gives it a nice easy alias....
|