我在maven设置文件〜/ .m2/settings.xml中默认激活了配置文件.
是否可以通过执行以下操作从命令行停用它:
mvn -P!profileActivatedByDefault
Run Code Online (Sandbox Code Playgroud) 我想忽略我的checkstyle报告中的特定文件夹(名为generated-sources),因为它们是生成的.
我正在使用eclipse-cs来显示我的违规行为.
我在我的xml中添加了一个suppressfilter:
<module name="SuppressionFilter">
<property name="file" value=".\suppressions.xml"/>
</module>
Run Code Online (Sandbox Code Playgroud)
我的suppressions.xml看起来像这样:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files="\*generated-sources\*\*\.\*" checks="[a-zA-Z0-9]*"/>
</suppressions>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.有任何想法吗?
我是android和java的新手.我一直在查看源代码并且微弱地想一想它可能是Java实现.
JavaDoc说如下:
AccessibleObject#getDeclaredAnnotations:
返回直接出现在此元素上的所有注释.与此接口中的其他方法不同,此方法忽略继承的注释.(如果此元素上没有直接出现注释,则返回长度为零的数组.)此方法的调用者可以自由修改返回的数组; 它对返回给其他调用者的数组没有影响.
返回此元素上的所有注释.(如果此元素没有注释,则返回长度为零的数组.)此方法的调用者可以自由修改返回的数组; 它对返回给其他调用者的数组没有影响.
由于getAnnotations是从类继承的java.lang.reflect.AccessibleObject,因此Field对象可以访问它.
据我所知,它们之间的唯一区别是getDeclaredAnnotations忽略了继承的注释.我在处理类时得到了它,但据我所知,Fields不能继承注释.
我无法在Groovy 2.1.9中调用递归闭包
def facRec = {long n->
return n>1 ? n * facRec(n - 1) : 1
}
Run Code Online (Sandbox Code Playgroud)
我得到了一个TypeMissmatch
Eclipse中是否有任何快捷方式允许我将字段添加到现有构造函数的参数列表中?
例:
我有这个课:
public class A {
int a;
int b;
public A(int a, int b) {
this.a = a;
this.b = b;
}
}
Run Code Online (Sandbox Code Playgroud)
当我添加一个字段int c(或许多字段)时,我想将它添加到构造函数的参数列表中并将参数分配给字段:
public class A {
int a;
int b;
int c; //this is new
public A(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
}
Run Code Online (Sandbox Code Playgroud)
我目前通过手动创建参数,然后按CTRL + 1,然后选择"将参数分配给字段"来完成此操作
但如果我一次添加多个字段,这不是一个很好的解决方案imho.
我不想创建一个新的构造函数!
我想使用go例程将for循环并行.我试过使用频道,但没有用.我的主要问题是,我希望在继续之前等待所有迭代完成.这就是为什么简单地写go之前它不起作用.我试图使用频道(我认为是错误的方式),但这使我的代码更慢
func createPopulation(populationSize int, individualSize int) []Individual {
population := make([]Individual, populationSize)
//i want this loop to be work parallel
for i := 0; i < len(population); i++ {
population[i] = createIndividual(individualSize)
}
return population
}
func createIndividual(size int) Individual {
var individual = Individual{make([]bool, size), 0}
for i := 0; i < len(individual.gene); i++ {
if rand.Intn(2)%2 == 1 {
individual.gene[i] = true
} else {
individual.gene[i] = false
}
}
return individual
}
Run Code Online (Sandbox Code Playgroud)
我的结构看起来像这样:
type Individual …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码:
List<Object> dest = new LinkedList<Object>();
Collections.copy(oldList, src);
Run Code Online (Sandbox Code Playgroud)
当我执行代码时,出现异常:
java.lang.IndexOutOfBoundsException: Source does not fit in dest
at java.util.Collections.copy(Collections.java:589)
Run Code Online (Sandbox Code Playgroud)
我知道如何解决这个问题,但是我不明白的是:
当我手动添加元素时,列表将自动增加容量。为什么Collections#copy不能这样做?
当我运行这个程序时:
class Baap {
public int h = 4;
public int getH() {
System.out.println("Baap " + h);
return h;
}
}
public class Beta extends Baap {
public int h = 44;
public int getH() {
System.out.println("Beta " + h);
return h;
}
public static void main(String[] args) {
Baap b = new Beta();
System.out.println(b.h + " " + b.getH());
Beta bb = (Beta) b;
System.out.println(bb.h + " " + bb.getH());
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
Beta 44
4 44
Beta 44 …Run Code Online (Sandbox Code Playgroud) 我的注释看起来像这样:
@Documented
@Target(ElementType.FIELD)
public @interface IsCrossSellingRevelant
{
boolean value() default true;
}
Run Code Online (Sandbox Code Playgroud)
我的ModelClass看起来像这样
public abstract class A {
@IsCrossSellingRevelant(true)
protected String someAnnotatedFiled;
protected String someFiled;
}
public class B extends A {
private String irrelevant;
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个方法应该给我在类层次结构中的注释字段
A object = new B();
Class<?> classIterator = object.getClass().getSuperclass();
do
{
for (Field field : classIterator.getDeclaredFields())
{
field.setAccessible(true);
IsCrossSellingRevelant isRelevant = field.getAnnotation(IsCrossSellingRevelant.class);
Annotation[] annotations = field.getDeclaredAnnotations();
Annotation[] annotations2 = field.getAnnotations();
}
classIterator = classIterator.getSuperclass();
}
while (classIterator != Object.class);
Run Code Online (Sandbox Code Playgroud)
但是,数组annotations和annotations2 …
field.setAccessible(false)对非私人领域有什么影响?
我希望拒绝访问这个成员,但事实并非如此!
我试图挖掘源代码,但在某些时候(Field#getFieldAccessor(Object))我忘记了发生了什么.
我为这种情况创建了一个特殊类:
public class DemoObject {
public Object publicMember = new Object();
protected Object protectedMember = new Object();
Object defaultMember = new Object();
private Object privateMember = new Object();
public final Object publicfinalMember = new Object();
protected final Object protectedfinalMember = new Object();
final Object defaultfinalMember = new Object();
private final Object privatefinalMember = new Object();
}
Run Code Online (Sandbox Code Playgroud)
并创建了一个演示:
import java.lang.reflect.Field;
public class MyMain {
public static void main(final String[] args) {
DemoObject object = new …Run Code Online (Sandbox Code Playgroud) $freeSlots = 0; //Unused local variable 'freeSlots'. The value of the variable is overwritten immediately.
if (strtotime($endDate) === strtotime($startDate))
{
return $endSlot - $startSlot;
}
else
{
$freeSlots = (5 - $startSlot) + ($endSlot - 1);
$newTime = strtotime('+1 day', $newTime);
if (date("Y-m-d", $newTime) === $endDate)
{
return $freeSlots;
}
do
{
if (!(date('N', $newTime) >= 6))
{
$freeSlots += 4;
}
$newTime = strtotime('+1 day', $newTime);
} while (date("Y-m-d", $newTime) !== $endDate);
}
return $freeSlots; //but is clearly used …Run Code Online (Sandbox Code Playgroud) 如何在 ubuntu 操作系统中使用 java 中的 swing 使用摄像头 请给我一些通过 java 使用摄像头的示例和指南。
public static void main(String[] args) {
CamDemo t = new CamDemo();
t.getCam();
}
public void getCam() {
try {
/* Grab the default web cam */
MediaLocator ml = new MediaLocator("vfw://0");
DataSource ds = Manager.createDataSource(ml);
requestFormatResolution(ds);
Player p = Manager.createRealizedPlayer(ds);
p.start();
Thread.currentThread().sleep(1000);
JFrame jfrm = new JFrame("Testing Webcam");
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (p.getVisualComponent() != null)
jfrm.getContentPane().add(p.getVisualComponent());
if (p.getControlPanelComponent() != null)
jfrm.getContentPane().add(p.getControlPanelComponent(),
BorderLayout.SOUTH);
jfrm.pack();
jfrm.setLocationRelativeTo(null);
jfrm.setVisible(true);
jfrm.setSize(320, 240);
} catch (Exception e) { …Run Code Online (Sandbox Code Playgroud) java ×8
annotations ×2
eclipse ×2
reflection ×2
android ×1
camera ×1
checkstyle ×1
collections ×1
concurrency ×1
for-loop ×1
go ×1
groovy ×1
inheritance ×1
list ×1
maven ×1
php ×1
phpstorm ×1
recursion ×1
swing ×1