This page in the Java tutorial got me very confused with question 2d. Looking at the Java documentation here, it appears that the static nested class javax.swing.Box.AccessibleBox is protected, so it can be accessed in subclasses or in the same package; while the inner class javax.swing.Box.Filler has the default access modifier – package-protected, right? – so it can be accessed from the same
Java教程中的这个页面让我非常困惑问题2d。 查看这里的Java文档,看起来静态嵌套类javax.swing.Box.AccessibleBox是受保护的,所以它可以在子类中或在同一个包中访问; 而内部类javax.swing.Box.Filler具有默认访问修饰符 - 包保护,对吧? - 所以它可以从同一个包中访问。 但是,只需在默认的Eclipse项目中创建一个简单的类: package sandbox; import javax.swing.Box; public class ExternalClass { Box.Filler var1;
Let's say, I am using a 3rd party jar A.jar in my project, with some members (classes, methods etc.) with default access (package private). Now, if I create the same package name in my project, I am able to access the members with default access modifier from A.jar (I tried this with Java Projects in Eclipse). Oracle's document says: If a class has no modifier (the default, also know
比方说,我在我的项目中使用第三方jar A.jar ,以及一些具有默认访问权限(包私有)的成员(类,方法等)。 现在,如果我在我的项目中创建相同的包名称,我可以使用A.jar中的默认访问修饰符访问成员(我在Eclipse中使用Java项目尝试过)。 甲骨文的文件说: 如果一个类没有修饰符(默认,也称为包私有),它只在它自己的包中可见 考虑到它不是A.jar的开发人员所想要的,这种哲学在这个特定用例(也没有使用反射)中A.jar
This question already has an answer here: Which is the default access specifier in Java? 11 answers From Java documentation If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.) At the member level , you can also use the public modifie
这个问题在这里已经有了答案: 哪一个是Java中的默认访问说明符? 11个答案 从Java文档 如果一个类没有修饰符(默认,也称为package-private),它只在它自己的包中可见(包是相关类的命名组 - 你将在后面的课中学习它们。) 在member level ,您也可以像使用顶级类一样使用public修饰符或no modifier (package-private),其含义相同。 你可以在这里阅读全文(我最近撰写的): http://codeinventions.blogspot.c
I am learning Java recently, and I came across the notion of package-private classes, which is the default if we don't specify anything. But then I realized: I seldom see the use of package-private class. Is there a reason for this, eg, it has serious drawbacks, it is redundant, or simply I am not reading enough? Are there strong arguments for/against its usage? If it is really not use
我最近在学习Java,并且遇到了package-private类的概念,如果我们没有指定任何类,这是默认类。 但后来我意识到: 我很少看到使用包私人类。 是否有这样的理由,例如,它有严重的缺点,是多余的,还是仅仅是我读得不够? 是否有强烈的争论/反对它的用法? 如果它在大多数情况下确实没有用,为什么它会成为默认值? 我们应该在什么情况下在现实世界中使用包私有的? 也就是说,它何时会成为不可替代的? 换句话说,默
Here are the brief definitions of encapsulation and abstraction. Abstraction: The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface). The only good example i see for this across different sites is interface. Encapsulation: Its basically about hiding the
以下是封装和抽象的简要定义。 抽象: Java中的抽象过程用于隐藏某些细节,仅显示对象的基本特征。 换句话说,它处理对象(接口)的外部视图。 我在不同网站上看到的唯一好例子就是界面。 封装: 它的基本原理是隐藏对象的状态,如私人,公共,受保护等修饰符的帮助下,我们只有在需要时才通过公共方法公开方法。 我们用private , public等修饰符实现的功能也会从外部世界隐藏不必要的细节,这只不过是一种抽象概念
I am taking my high school AP Computer Science class. I decided to throw a goto statement into a one of our labs just to play around, but I got this error. Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "goto", assert expected restart cannot be resolved to a variable at Chapter_3.Lab03_Chapter3.Factorial.main(Factorial.java:28) I we
我正在参加我的高中AP计算机科学课。 我决定向我们的一个实验室扔一个goto声明来玩,但是我得到了这个错误。 Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "goto", assert expected restart cannot be resolved to a variable at Chapter_3.Lab03_Chapter3.Factorial.main(Factorial.java:28) 我在Stackoverflow上找到了一个goto问题,以了解如何正确地做
Given the value, I need to get the index or key which this value belongs in a Map without the need to iterate it. I'm using java. Thanks Guava has a BiMap, which is a bidirectional map (each key and each value are unique). If you don't waht to use an external library, you only have 2 options: use a plain HashMap and you will need to iterate over the keys use 2 hashmaps, one rel
给定值,我需要在Map中获取该值所属的索引或关键字,而无需迭代它。 我正在使用java。 谢谢 番石榴有一个BiMap,它是一个双向映射(每个键和每个值都是唯一的)。 如果您不想使用外部库,则只有两种选择: 使用普通的HashMap ,你需要遍历键 使用2个hashmaps,一个关联数值,另一个关联数值(这实质上是双向映射的作用)。 您始终可以使用公用集合中的BidiMap: http://commons.apache.org/collections/apidocs/o
I'm working on setting new tab orders for multiple Panels accross an application. I want to create a new class that will allow me to handle to sorting much in the same way as the deprecated setNextFocusableComponent method would. I'm creating a class that extends the DefaultTreversalPolicyClass and overloads the getComponentBefore and getComponentAfter methods. On the panels themselves
我正在为应用程序中的多个面板设置新的Tab键顺序。 我想创建一个新的类,这将允许我像处理过的setNextFocusableComponent方法一样处理大量的排序。 我创建了一个扩展DefaultTreversalPolicyClass并且重载getComponentBefore和getComponentAfter方法的类。 在面板本身上,我希望实现与创建新的自定义类(我将其称为CustomizedTabOrderPolicy)一样简单,然后添加要为其指定Tab键顺序的组件。 我通过CustomizedTabOrderPolicy
I like how Java has a Map where you can define the types of each entry in the map, for example <String, Integer> . What I'm looking for is a type of collection where each element in the collection is a pair of values. Each value in the pair can have its own type (like the String and Integer example above), which is defined at declaration time. The collection will maintain its given
我喜欢Java如何在Map中定义地图中每个条目的类型,例如<String, Integer> 。 我在寻找的是一种集合,其中集合中的每个元素都是一对值。 对中的每个值都可以有自己的类型(如上面的String和Integer示例),它在声明时定义。 该集合将保持其给定顺序,并不会将其中一个值视为唯一键(如在地图中)。 基本上我希望能够定义一个类型为<String,Integer>或任何其他2种类型的ARRAY。 我意识到我可以只用2个变量来
There's a good discussion of Generics and what they really do behind the scenes over at this question, so we all know that Vector<int[]> is a vector of integer arrays, and HashTable<String, Person> is a table of whose keys are strings and values Person s. However, what stumps me is the usage of Class<> . The java class Class is supposed to also take a template name, (or s
关于泛型和他们在这个问题背后的真实情况有很好的讨论,所以我们都知道Vector<int[]>是一个整型数组的向量,而HashTable<String, Person>是一个表,其键是字符串和值Person 。 然而,让我感到困惑的是Class<>的用法。 java class Class应该也采用模板名称,(或者我被eclipse中的黄色下划线告知)。 我不明白我应该放在那里。 Class对象的全部重点是当你没有完全掌握关于对象的信息,反射等等。 为什么