access-modifiers

Scala parameters for access modifiers?

扶醉桌前 提交于 2019-12-20 01:10:19
问题 What is the difference between class Test { private[this] val foo = 0 } vs class Test { private val foo = 0 } What all can go inside the [] ? Also, what should I search for when I want to look up the specs of this? I tried Googling various combinations of "scala access modifier arguments/parametrized scala access modifier" and nothing came up. 回答1: what should I search for when I want to look up the specs of this? In The Scala Language Specification it is defined as "access modifier" and

Java Package level access

风流意气都作罢 提交于 2019-12-19 21:47:48
问题 I know that class members with default access control can be accessible at package level but i'm confused about what does package level access actually mean. If default members can be accessed at package level then shouldn't i be visible in class Test2 in following example? class 1- package pkg1; public class Test { int i=0; } class 2- import pkg1.Test; public class Test2 { void get(){ Test t = new Test(); t.i=0; } } Please help me getting this concept. Thanks in advance. 回答1: Package level

Inconsistent accessibility: return type is less accessible than method C#

99封情书 提交于 2019-12-18 19:18:23
问题 Ok, so this is really wierd. I have a private member, and I want to use it into Form2. I've made a public static method, so that I can get that member into Form2. Here is my code: private static AppController appController; private BreadRepository breadRep; private CakeRepository cakeRep; private SandwichRepository sandwichRep; public Form1() { InitializeComponent(); breadRep = new BreadRepository(); cakeRep = new CakeRepository(); sandwichRep = new SandwichRepository(); appController = new

Private constructor inhibits use of emplace[_back]() to avoid a move

醉酒当歌 提交于 2019-12-18 18:59:22
问题 Consider the following code: #include <vector> class A { public: A(A&&); // somewhat expensive static std::vector<A> make_As() { std::vector<A> result; result.push_back(A(3)); result.push_back(A(4)); return result; } private: A(int); // private constructor }; Since A 's move constructor is somewhat expensive (for whatever reason), I'd like to avoid calling it and use emplace_back() instead: #include <vector> class A { public: A(A&&); // somewhat expensive static std::vector<A> make_As() { std

Changes in access of variables for generic classes in Java 7

蹲街弑〆低调 提交于 2019-12-18 14:17:43
问题 Here is a simple example of some code that compiles using Java 6, but does not compile in Java 7. public class Test<T extends Test> { private final int _myVar; public Test(int myVar) { _myVar = myVar; } public int get(TestContainer<T> container){ T t = container.get(); return t._myVar; } private static class TestContainer<T extends Test> { private final T _test; private TestContainer(T test) { _test = test; } public T get(){ return _test; } } } In Java 7, it fails to compile in the get

How to access an internal Swift class in Objective-C within the same framework?

倖福魔咒の 提交于 2019-12-18 12:58:20
问题 Working on a mixed framework. imported inside the Obj-C file but the internal classes are not visible, only the public ones. The documentation clearly states the internal clasees should be available between Swift and Obj-C: Importing Swift into Objective-C To import a set of Swift files in the same framework target as your Objective-C code, you don’t need to import anything into the umbrella header for the framework. Instead, import the Xcode-generated header file for your Swift code into any

Change the access modifier of an overridden method in Java?

荒凉一梦 提交于 2019-12-18 11:32:31
问题 Is there a reason one can change the access modifier of an overridden method? For instance, abstract class Foo{ void start(){...} } And then change the package-private access modifier to public , final class Bar extends Foo{ @Override public void start(){...} } I'm just asking this question out of curiosity. 回答1: Java doesn't let you make the access modifier more restrictive , because that would violate the rule that a subclass instance should be useable in place of a superclass instance. But

final variables are not functioning well in jshell

好久不见. 提交于 2019-12-18 05:02:23
问题 I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is

final variables are not functioning well in jshell

与世无争的帅哥 提交于 2019-12-18 05:01:02
问题 I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is

C# - Improving encapsulation of property in this example?

狂风中的少年 提交于 2019-12-18 04:43:14
问题 I know of the error "The accessibility modifier of the set accessor must be more restrictive than the property or indexer". I also know the solution. Just not in this very specific case. Consider this example: internal virtual bool IsFocused { get { return isFocused; } protected set { isFocused = value; } } private bool isFocused; It shows the error. I just don't know why. How is "protected" not less accessible than internal? What would be the solution to this problem? I tried putting