public-method

public methods in package-private classes

折月煮酒 提交于 2019-11-27 18:29:11
Does it make a difference to mark methods as public in package-private classes? class SomePackagePrivateClass { void foo(); // package private method public void bar(); // public method } Is there any practical difference in visibility between foo and bar here? If the class is not going to be extended by another, more visible subclass*, the only difference is clarity of intent . Declaring all methods package private makes it more difficult for future readers to determine which of the methods are meant to be called by other classes in the same package. * which would not make much sense as a

How to retrieve all public methods from *.dll

旧巷老猫 提交于 2019-11-27 15:04:40
问题 I have *.dll written with C# and I need to get list of all public methods or classes contained in that *.dll. Is there some way to do it programmatically with C#? 回答1: Yes use Assembly.GetTypes to extract all of the types, and then use reflection on each type to iterate the public methods. Assembly a = Assembly.LoadWithPartialName("..."); Type[] types = a.GetTypes(); foreach (Type type in types) { if (!type.IsPublic) { continue; } MemberInfo[] members = type.GetMembers(BindingFlags.Public

Reference to a non-shared member requires an object reference occurs when calling public sub

血红的双手。 提交于 2019-11-27 06:35:57
问题 I have a Public Class "General" in which is a Public Sub "updateDynamics". When I attempt to reference it in the code-behind for a page like so: updateDynamics(get_prospect.dynamicsID) I get the following error: reference to a non-shared member requires an object reference 回答1: You either have to make the method Shared or use an instance of the class General : Dim gen = New General() gen.updateDynamics(get_prospect.dynamicsID) or General.updateDynamics(get_prospect.dynamicsID) Public Shared

public vs. internal methods on an internal class

亡梦爱人 提交于 2019-11-27 04:19:45
问题 internal class Foo { public void Fee() { Debug.WriteLine("Fee"); } internal void Fi() { Debug.WriteLine("Fi"); } } I'm thinking that Fee() and Fi() are equally accessible since the entire class is already internal. Am I overlooking something? Is there any reason to choose public or internal for the methods in a case like this? 回答1: The internal class Foo declaration will override the accessibility of the public void Fee() method, effectively making it internal. In this case, using internal vs

Why should we declare interface methods as public? [duplicate]

人盡茶涼 提交于 2019-11-27 01:15:12
问题 This question already has answers here : Protected in Interfaces (15 answers) Closed 2 years ago . When I implement an interface method, I am forced to make it a public method. We may have cases where we want to use either the default (like in case of access within the same package) or protected . Can anyone please explain the reason behind this limitation? 回答1: Interfaces are meant to define the public API of a type - and only that, not its implementation. So any method (or static member)

Access Of Public Method Between Forms

别来无恙 提交于 2019-11-26 21:04:43
问题 I am trying to get access to Form1’s public method on another form Form2 as below. I have a textbox6 control on form1 and there is public method to bind it. But I want to bind it by form2 as below. Form1 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.Show(); } public void amount_sum() { string connstr = " server=.;initial catalog=maa;uid=mah;pwd=mah"; SqlConnection con = new

public methods in package-private classes

痴心易碎 提交于 2019-11-26 19:27:44
问题 Does it make a difference to mark methods as public in package-private classes? class SomePackagePrivateClass { void foo(); // package private method public void bar(); // public method } Is there any practical difference in visibility between foo and bar here? 回答1: If the class is not going to be extended by another, more visible subclass*, the only difference is clarity of intent . Declaring all methods package private makes it more difficult for future readers to determine which of the

Should methods in a Java interface be declared with or without a public access modifier?

↘锁芯ラ 提交于 2019-11-26 19:18:36
Should methods in a Java interface be declared with or without the public access modifier? Technically it doesn't matter, of course. A class method that implements an interface is always public . But what is a better convention? Java itself is not consistent in this. See for instance Collection vs. Comparable , or Future vs. ScriptEngine . Jon Skeet The JLS makes this clear: It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface. The public modifier should be omitted in Java interfaces (in my

Disable “not used” warning for public methods of a class

强颜欢笑 提交于 2019-11-26 18:07:00
问题 The new intellij upgrade (10.5) now shows a warning that some of the methods defined for a class are not being used. These methods are public and I plan on not using all of them as I have created them to support the API expected. I would like to disable this warning (not used for public methods in a class). Is there a way to do it?. 回答1: You can disable it for a single method like this @SuppressWarnings("unused") public void myMethod(){...} 回答2: IDEA 2016.3 In the upcoming version IDEA 2016.3