Local variable counter defined in an enclosing scope must be final or effectively final.


    @Test

    public void counterTest() {

    int count = 0;

   

    IntStream.range(0, 10)

    .forEach(i -> {

    count++; // Local variable count defined in an enclosing scope must be final or effectively final

    });

   

    System.out.println(count);

    }



[증상]


익명함수에서 로컬변수를 수정할 수 없는 현상.




[해결방법]


1. 로컬변수를 클래스 멤버로 변경한다.


    int count;

    

    @Test

    public void counterTest() {

    count = 0;

   

    IntStream.range(0, 10)

    .forEach(i -> {

    count++; // OK

    });

   

    System.out.println(count);

    }



2. AtomicInteger 를 사용한다.


    @Test

    public void counterTest() {

    AtomicInteger count = new AtomicInteger(0);

   

    IntStream.range(0, 10)

    .forEach(i -> {

    count.incrementAndGet();

    });

   

    System.out.println(count.get());

    }


3. array를 사용하는것도 같은 방법.


    @Test

    public void counterTest() {

    final int[] count = { 0, };

   

    IntStream.range(0, 10)

    .forEach(i -> {

    count[0]++;

    });

   

    System.out.println(count[0]);

    }


https://stackoverflow.com/a/30213098



4. Consumer... 



** Anaconda3 python 3.6 version




> pip install gym


> pip install --no-index -f https://github.com/Kojoley/atari-py/releases atari_py


> pip install gym['atari']
















Microsoft Visual C++ 14.0 required


http://landinghub.visualstudio.com/visual-cpp-build-tools



Visual Studio 2015 Uninstall


https://github.com/Microsoft/VisualStudioUninstaller/releases 

윈도10에서 배시를 지원하기는 하지만


GUI 프로그램을 실행할 수는 없다.


이때 윈도우용 X Server 프로그램인 Xming을 설치 하면 GUI 프로그램도 실행 할 수 있다.


https://sourceforge.net/projects/xming/



export DISPLAY=:0


설정은 배시가 종료되면 사라지므로 GUI 프로그램을 실행하기 전에 항상 설정해 주어야 한다.






https://www.howtogeek.com/261575/how-to-run-graphical-linux-desktop-applications-from-windows-10s-bash-shell/

'리눅스' 카테고리의 다른 글

Docker offline install  (0) 2016.07.29
XP Boot Error: "xmnt2002 program not found - skipping AUTO CHECK"  (0) 2010.11.29

public void TestMinDistance()

{

List<Point> list = new List<Point>()

{

new Point(1, 1),

new Point(2, 1),

new Point(2, 0),

};


Point pivot = new Point(3, 1);


Func<Point, Point, double> DistanceTo = (point1, point2) =>

{

var a = (double)(point2.X - point1.X);

var b = (double)(point2.Y - point1.Y);


return Math.Sqrt(a * a + b * b);

};


Point nearest = list

.Aggregate((x, y) => DistanceTo(x, pivot) < DistanceTo(y, pivot) ? x : y);


Debug.WriteLine(nearest);


// sort by distance

List<Point> sortedList = list

.OrderBy(x => DistanceTo(x, pivot))

.ToList();


sortedList.ForEach(p => Debug.WriteLine(p));

}



https://stackoverflow.com/a/5954005

http://www.vcskicks.com/code-snippet/distance-formula.php

+ Recent posts