public

Objective-C static, extern, public variables

孤人 提交于 2019-11-28 15:28:46
I want to have a variable that I can access anywhere by importing a header file but I also want it to be static in the sense that there is only one of them created. In my .m file, I specify static BOOL LogStuff = NO; and in the initialize method I set the logging value: + (void)initialize { LogStuff = ... //whatever } However I want to be able to access my variable anywhere by importing the .h file so I want to do something like this: static extern BOOL LogStuff; but I'm not allowed to do that. Is it possible to do the thing I'm trying to do? Thanks Adam Rosenfield static in Objective-C means

Why @Rule annotated fields in JUnit has to be public?

徘徊边缘 提交于 2019-11-28 13:15:38
In JUnit test case, a field annotated by @Rule must be public. It breaks a common Java coding convention (all class member variables should not be public). Why does JUnit require this? Documentation for @Rule : https://github.com/junit-team/junit/blob/master/src/main/java/org/junit/Rule.java The JUnit runner will need to access the field reflectively to run the rule. If the field was private the access would throw IllegalAccessException . Another option would have been to have the runner modify the access from private to public before running the rule. However that could cause problems in case

C# public variable as writeable inside the class but readonly outside the class

ε祈祈猫儿з 提交于 2019-11-28 09:35:57
I have a .Net C# class where I need to make a variable public. I need to initialize this variable within a method (not within the constructor). However, I don't want the variable to be modifieable by other classes. Is this possible? Don't use a field - use a property: class Foo { public string Bar { get; private set; } } In this example Foo.Bar is readable everywhere and writable only by members of Foo itself. As a side note, this example is using a C# feature introduced in version 3 called automatically implemented properties . This is syntactical sugar that the compiler will transform into a

Is it possible to declare a public variable in vba and assign a default value?

五迷三道 提交于 2019-11-28 09:35:04
I want to do this but it won't compile: Public MyVariable as Integer = 123 What's the best way of achieving this? .NET has spoiled us :) Your declaration is not valid for VBA. Only constants can be given a value upon application load. You declare them like so: Public Const APOSTROPHE_KEYCODE = 222 Here's a sample declaration from one of my vba projects: If you're looking for something where you declare a public variable and then want to initialize its value, you need to create a Workbook_Open sub and do your initialization there. Example: Private Sub Workbook_Open() Dim iAnswer As Integer

“The constructor is not visible” error

怎甘沉沦 提交于 2019-11-28 09:11:25
问题 I have two classes : First, with one constructor : public class First { First (ObjectA myObjectA) { //do stuff } } And Second, with two constructors : public class Second { Second (ObjectB myObjectB) { //do something... } Second (ObjectC myObjectC) { //do something else... } } When I want to instantiate my First class, Eclipse generates me an error ("The constructor is not visible"), I have to add public to the constructor of First : First first = new First(myObject); //Error : "The

Reasons to avoid access modifiers in php [closed]

六眼飞鱼酱① 提交于 2019-11-28 08:49:43
What are valid reasons NOT to use keywords public, private, protected in php? The story: I've started a project with a team that actively uses access modifiers in their code (even "public" explicitly) and wants to convince me to do the same. I always find this kind of stuff totally useless in a dynamic language like php, but I realize that my gut feeling is hardly an argument in a technical discussion. Therefore I'm looking for a solid, clear explanation why access modifiers are useless (or even harmful) in php. I'm aware that some similar topics already exist Importance of protected/private

Public property VS Private property with getter?

荒凉一梦 提交于 2019-11-28 07:48:12
问题 This question has puzzled me for a while. A public property that can be accessed directly or a private property with getter? Which one is better/correct and why? 回答1: Exposing fields directly is considered a bad practice. It is better to keep the field private and only expose the getter and setter. One advantage is that you can choose different access levels for the getter and setter, whereas a field has only a single access level. Another advantage of using getters is that it allows you to

How to access an object's public fields from a Velocity template

早过忘川 提交于 2019-11-28 07:21:19
问题 Here is my object class: public class Address { public final String line1; public final String town; public final String postcode; public Address(final String line1, final String town, final String postcode) { this.line1 = line1; this.town = town; this.postcode = postcode; } } I add it to the velocity context like this: Address theAddress = new Address("123 Fake St", "Springfield", "SP123"); context.put("TheAddress", theAddress); However, when writing the template, the following will not

Protecting the content of public/ in a Rails app

假装没事ソ 提交于 2019-11-28 04:34:39
I'm maintaining a Rails app that has content in the public/ folder that will now need to be protected by a login. We're considering moving those folders of files into a path outside of public/ and writing a Rails controller to serve up the content. Before we begin writing this, I was curious if anyone else has ran into this sort of problem? I looked for some gems / plugins that might already do this but didn't find anything. Has anyone created a gem for this? I've done this on a site where people pay to download certain files, and the files are stored in RAILS_ROOT/private . The first thing to

Run a script.php on cron job on linux/apache server but restrict public access to the php file

旧时模样 提交于 2019-11-28 03:55:33
问题 I have this script.php file which i want to run as a cron job on my linux/apache server. However, i do not want public to access www.mycompanyname.com/script.php and also run the script concurrently. How can we prevent that? How can we restrict the script to the server's access only? Is it using chmod or setting something inside .htaccess file, something along the line? Any advice ? 回答1: You probably have something like a public_html directory, in which you have all the phps. Just put it