Java报错-静态方法不能直接调用非静态方法
1. 报错提示:
Cannot make a static reference to the non-static method quickSort(int[], int, int) from the type L912手撕快速排序Java(603979977)
void L912手撕快速排序.quickSort(int[] nums, int low, int high)
2. 报错原因
-
quickSort 和 partition 不是静态方法
你在 sortArray 里直接调用了 quickSort(nums, 0, nums.length - 1);,
但 quickSort 和 partition 都是非静态方法,而 sortArray 是静态方法,
静态方法不能直接调用非静态方法。 -
解决方法:
要么把 quickSort 和 partition 都改成 static,
要么把 sortArray 也改成非静态方法,或者用对象调用。

浙公网安备 33010602011771号