public

How to publish ports in docker files

為{幸葍}努か 提交于 2019-11-27 15:38:35
问题 I need to map the ports on the host to the ports on the container. I can achieve this by running the "docker run" command with the -p option. How do I achieve this through the Dockerfile ? Using the following gives a "deprecated error" EXPOSE 80:8080 How else can I make the exposed ports public through teh dockerfile? 回答1: You can't. What ports are published on the docker host is strictly a decision that should be made by the local administrator, not by the image they are trying to run; this

C# winform: Accessing public properties from other forms & difference between static and public properties

旧巷老猫 提交于 2019-11-27 15:12:42
I am trying to understand whats the difference between a static and public properties. But when I tried to access my public property 'Test' in other form it says 'null'. Heres Form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string _test; public string Test { get { return _test; } set { _test = value; } } private void Form1_Load(object sender, EventArgs e) { _test = "This is a test"; } private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } } Here's Form2: public partial class Form2 : Form { public Form2() {

Setting public class variables

☆樱花仙子☆ 提交于 2019-11-27 14:48:42
问题 How do I set a public variable. Is this correct?: class Testclass { public $testvar = "default value"; function dosomething() { echo $this->testvar; } } $Testclass = new Testclass(); $Testclass->testvar = "another value"; $Testclass->dosomething(); 回答1: this is the way, but i would suggest to write a getter and setter for that variable. class Testclass { private $testvar = "default value"; public function setTestvar($testvar) { $this->testvar = $testvar; } public function getTestvar() {

How to prevent public methods from being called from specific classes

本秂侑毒 提交于 2019-11-27 14:22:36
I have an existing class into which I want to add a method. But I want the method to be called only from a specific method from a specific class. Is there any way that I can prevent that call from other classes/methods? For example, I have an existing class A public final class A { //other stuff available for all classes/methods //I want to add a method that does its job only if called from a specific method of a class, for example: public void method() { //proceed if called from Class B.anotherMethod() else throw Exception } } One way of doing this is getting the StackTrace inside the method(

Difference between public static and private static variables

徘徊边缘 提交于 2019-11-27 11:43:56
class Employee{ // salary variable is a private static variable private static double salary; // DEPARTMENT is a constant public static final String DEPARTMENT = "Development"; public static void main(String args[]){ salary = 1000; System.out.println(DEPARTMENT+ " average salary:"+salary); } } This java program contains a static variable. But I cannot understand the difference between public and private static variables. A public variable is accessible everywhere in the code - a private variable is only accessible within the class itself. In this case you're using Employee.salary within the

Use of “Public” in a derived class declaration?

徘徊边缘 提交于 2019-11-27 11:12:49
问题 Given this base class: class Employee { char* name; int age; public: Employee(char* name); void print(); }; With regards to the "public", what's the difference between this: class Manager : public Employee { EmployeeList employees; public: Manager(char* name, Employee* people); void print(); }; and this: class Manager : Employee { EmployeeList employees; public: Manager(char* name, Employee* people); void print(); }; 回答1: The default is private inheritance. take this example: class B { };

What if main method is inside “non public class” of java file?

半腔热情 提交于 2019-11-27 09:29:08
I have a java file containing more than one class, out of which one is public. If main method is inside a non-public class. I can't run that java file. Why is that? and there is no compilation error as well. If so, how can I use that main method? You can certainly override main method and it does not violate any compiler rules and hence you will not have any compiler errors. You check that inspite of the fact that you have more than one class a file that is declared as public is the name of the file you are trying to execute. This is a convention that the file should be named after the same

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

余生长醉 提交于 2019-11-27 07:43:09
问题 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 回答1: 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

The name '…' does not exist in the current context

余生长醉 提交于 2019-11-27 05:38:20
I have a list within my Main() and I'm trying to add an item to that list from within a variable. But it's throwing the error "The name 'dogList' does not exist in the current context" Inside my addDog() method, dogList.Add() is not working due to above. namespace DoggyDatabase { public class Program { public static void Main(string[] args) { // create the list using the Dog class List<Dog> dogList = new List<Dog>(); // Get user input Console.WriteLine("Dogs Name:"); string inputName = Console.ReadLine(); Console.WriteLine("Dogs Age:"); int inputAge = Convert.ToInt32(Console.ReadLine());

What does `public static void main args` mean?

笑着哭i 提交于 2019-11-27 05:12:24
I am not sure what this means, whenever before you write a code, people say this public static void main(String[] args) { What does that mean? Sai Upadhyayula Here is a little bit detailed explanation on why main method is declared as public static void main(String[] args) Main method is the entry point of a Java program for the Java Virtual Machine(JVM). Let's say we have a class called Sample class Sample { static void fun() { System.out.println("Hello"); } } class Test { public static void main(String[] args) { Sample.fun(); } } This program will be executed after compilation as java Test .