private

Private constructor in abstract class

允我心安 提交于 2019-11-29 12:16:22
问题 In Java what is the purpose of using private constructor in an abstract class? In a review I got this question, and I am curious, for what situation we need to use the constructor in such way? I think it can be used in pair with another constructor in abstract class, but this is very trivial. Also it can be used for constructing static inner classes which will excend abstract class. Maybe there is more elegant usage? 回答1: If the private constructor is the only constructor of the class, then

Calling private function within the same class python

折月煮酒 提交于 2019-11-29 11:17:13
问题 How can i call a private function from some other function within the same class? class Foo: def __bar(arg): #do something def baz(self, arg): #want to call __bar Right now, when i do this: __bar(val) from baz(), i get this: NameError: global name '_Foo__createCodeBehind' is not defined Can someone tell me what the reason of the error is? Also, how can i call a private function from another private function? 回答1: There is no implicit this-> in Python like you have in C/C++ etc. You have to

JavaDoc for private / protected methods? [closed]

会有一股神秘感。 提交于 2019-11-29 10:33:21
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Should I write JavaDoc for private or protected methods? And what about private variables? I see class examples on my Java book and the private variables are JavaDoc'ed. So I can't understand if it is a good practice to JavaDoc the private (or protected ) methods. 回答1: Yes

Hide instance variable from header file in Objective C

给你一囗甜甜゛ 提交于 2019-11-29 10:06:57
问题 I came across a library written in Objective C (I only have the header file and the .a binary). In the header file, it is like this: @interface MyClass : MySuperClass { //nothing here } @property (nonatomic, retain) MyObject anObject; - (void)someMethod; How can I achieve the same thing? If I try to declare a property without its corresponding ivar inside the interface's {}, the compiler will give me an error. Ultimately, I want to hide the internal structure of my class inside the .a, and

Private method in groovy is not private

廉价感情. 提交于 2019-11-29 09:14:47
class A { private def sayHello() { println "Anish" } } def a_obj = new A() a_obj.sayHello() output : Anish Is there any way to protect sayHello() in groovy or am I missing something? Andrey Adamovich There is defect on that in Groovy issue tracking system and that defect is still open. tim_yates Searching for [groovy] private reveals: groovy call private method in Java super class What does 'private' mean in Groovy? How to define private getter method in Groovy Bean? It's not clear if it is a bug or by design, but it is going to get looked at again in Groovy 2.0 Jason You can use closures to

Are synthesized instance variables generated as private instead of protected?

孤街浪徒 提交于 2019-11-29 07:49:35
Since recent runtimes in iOS, we are able to define properties that will generate accessors for instance variables. From what I understand, it is not mandatory to declare the instance variable used since it will be automatically done for us. For example, if I write: @interface MyFirstClass @property (readonly, nonatomic) int size; @end and in the .m @implementation MyFirstClass @synthesize size; @end Then an instance variable named "size" will be added for me and a method called "-(int)size" will be implemented. The problem is that when I create a second class MySecondClass which is a subclass

Tuple struct constructor complains about private fields

泪湿孤枕 提交于 2019-11-29 05:35:48
I am working on a basic shell interpreter to familiarize myself with Rust. While working on the table for storing suspended jobs in the shell, I have gotten stuck at the following compiler error message: error: cannot invoke tuple struct constructor with private fields [E0450] let jobs = job::JobsList(vec![]); ^~~~~~~~~~~~~ It's unclear to me what is being seen as private here. As you can see below, both of the structs are tagged with pub in my module file. So, what's the secret sauce? mod job { use std::fmt; pub struct Job { jid: isize, pid: isize, cmd: String, } pub struct JobsList(Vec<Job>)

Why explicitly write “private”?

无人久伴 提交于 2019-11-29 05:26:12
As fields are implicitly private, why there is often explicit declaraion used in the books, articles etc.? Because default access levels vary across languages, and many people program in more than one language. It's easy to become confused, either as the author or as someone reading the code later, thus explicit is nicer to deal with than implicit. The problem with implicit declarations is that the reader cannot tell if whoever wrote the code wanted the implicit declaration or simply forgot to write anything. By being explicit there's no doubt about the intentions. To make your code look nice

Objective-c: why private ivars are not hidden from the outside access when using KVC

孤街醉人 提交于 2019-11-29 02:20:54
After trying to access ivars using KVC, I have noticed that there was no protection on private and protected ivars. It doesn't matter what I put a in front of the ivar (private or protected keyword) - an ivar is always a public ivar when using KVC method "setValue". Here is my code where all of the seven ivars and properties are changeble outside the class instance: //************ interface file ***************// @interface MyClass : NSObject { @public NSNumber *public_num; @protected NSNumber *protected_num; @private NSNumber *private_num; NSNumber *private_property; } @property (retain)

Private class (not class method) in a Ruby module?

独自空忆成欢 提交于 2019-11-29 01:26:27
I'm new to Ruby (experienced with Python, C++ and C). I need to create a class that is only to be used by other classes and methods in a module. In Python, I'd just call it __classname. I'd use an empty typedef in C++. How do I do this in Ruby (or am I barking up the wrong tree and not doing this the "Ruby way"?) I haven't seen such concept so far in Ruby, but I guess you could simulate that by creating private method which would return a class created as a local variable (remember that in Ruby, a class is an object just like any other, and can be instantiated in a method and returned by it).