private

Java: Accessing private fields directly from another instance of the same class

烂漫一生 提交于 2019-12-03 12:29:37
I'm writing a equals(Object obj) function for a class. I see that it is possible to access the private fields of obj from the caller. So instead of using a getter: Odp other = (Odp) obj; if (! other.getCollection().contains(ftw)) { } I can just access the field directly: Odp other = (Odp) obj; if (! other.collection.contains(ftw)) { } Is this bad practice? No, it's not. The reason that private variables and methods are not accessable from other classes is to allow you to change the internals of your class without having to change all the code that uses the class (that and to prevent the user

Why is it legal to inappropriately access privates in an explicit instantiation?

白昼怎懂夜的黑 提交于 2019-12-03 12:06:42
问题 Why on earth would this be allowed: ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// template<typename T> struct invisible { static typename T::type value; }; template<typename T> typename T::type invisible<T>::value; ////////////////////////////////////////////////////////////////////////// template<typename T, typename T::type P> class construct_invisible { construct_invisible(){ invisible<T

iOS: Using @private to hide properties from being set

风格不统一 提交于 2019-12-03 11:29:16
问题 I am wring a class that has a bunch of properties that I want to only use internally. Meaning I don't want to be able to have a user access them when they have created my class. Here is what I have in my .h but it still doesn't hide those from the autocomplete menu (hitting escape to see list) in XCode: @interface Lines : UIView { UIColor *lineColor; CGFloat lineWidth; @private NSMutableArray *data; NSMutableArray *computedData; CGRect originalFrame; UIBezierPath *linePath; float point; float

C++: Why must private functions be declared?

∥☆過路亽.° 提交于 2019-12-03 09:27:34
Why do classes in C++ have to declare their private functions? Has it actual technical reasons (what is its role at compile time) or is it simply for consistency's sake? I asked why private functions had to be declared at all, as they don't add anything (neither object size nor vtable entry) for other translation units to know If you think about it, this is similar to declaring some functions static in a file. It's not visible from the outside, but it is important for the compiler itself. The compiler wants to know the signature of the function before it can use it. That's why you declare

Design decisions: Why and when to make an interface private?

心不动则不痛 提交于 2019-12-03 09:04:45
问题 Are private interfaces ever used in design decisions ? If so, what are the reasons and when do you know the need for a private interface? 回答1: A top-level interface cannot be private. It can only have public or package access. From the Java Language Specification, section 9.1.1: "Interface Modifiers": The access modifiers protected and private pertain only to member interfaces whose declarations are directly enclosed by a class declaration (§8.5.1). A nested interface can be private whenever

PubNub best practice: How to manage private rooms?

故事扮演 提交于 2019-12-03 09:00:00
I'm learning pubnub and I read their documentation but I just can't find how to manage a multi room chat box. By default, a channel can be listened by anyone. Subscribing to it and publishing on it is easy. What I want is to have a main public room (so far so good) but anyone should also be able to talk privately to anyone else without the risk of being read by other users. These dynamic rooms would be tabbed and the user should be able to go from one to another. Another requirement would be that talking privately to someone doesn't kick you out of the other rooms you subscribed to (you can

Viewing private files created by an android app

≯℡__Kan透↙ 提交于 2019-12-03 08:36:00
问题 I have an xml file being written by an app that is set to MODE_PRIVATE, but I now want to read that file outside of the phone, for debugging purposes. In Eclipse, I can access other files made by the app and copy them to my computer, but I can't even see this private file. Merely changing the file to MODE_WORLD_READABLE file doesn't seem to help. I think the file is being stored on an internal "SD card" that can not be removed from the phone, but there are also two other folders in the File

How can I embed private youtube video in my site?

☆樱花仙子☆ 提交于 2019-12-03 06:30:50
问题 I have to display some private Youtube videos in my blog. I cannot embed them directly. What should I use to do this. 回答1: I do not think you can embed private youtube videos on your site and even if you do, they will not be able to view it because it's private. 回答2: You should set your videos to "unlisted" instead of "private". That way the video does not show up on your channel or on any search results but anyone with a link to the video can see it and you can embed the video on any site.

Testing private class member in C++ without friend [duplicate]

限于喜欢 提交于 2019-12-03 05:01:32
问题 This question already has answers here : How do I test a private function or a class that has private methods, fields or inner classes? (51 answers) Closed last year . Today I had a discussion with a colleague on whether to test or not to test private members or private state in the class. He almost convinced me why it makes sense. This question does not aim to duplicate already existing StackOverflow questions about the nature and reason of testing private members, like: What is wrong with

In C# 4.0, is there any way to make an otherwise private member of one class available only to a specific other class?

好久不见. 提交于 2019-12-03 04:58:14
问题 We're creating an object hierarchy where each item has a collection of other items, and each item also has a Parent property pointing to its parent item. Pretty standard stuff. We also have an ItemsCollection class that inherits from Collection<Item> which itself has an Owner property pointing to the item the collection belongs to. Again, nothing interesting there. When an item is added to the ItemsCollection class, we want it to automatically set the parent of Item (using the collection's